r/programming • • Jul 25 '13

CoffeeScript's Scoping is Madness

http://donatstudios.com/CoffeeScript-Madness
207 Upvotes

315 comments sorted by

View all comments

Show parent comment

2

u/rwbarton Jul 26 '13

Yes. That code is equivalent to

var counter1;

counter1 = (function() {
  var i = 0;
  return function() {
    return i++;
  };
})();

which is what you wanted, I think. As far as I know you cannot write CoffeeScript that compiles to the above javascript exactly.