MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/1j1cw7/coffeescripts_scoping_is_madness/cbag8at/?context=3
r/programming • u/donatj • Jul 25 '13
315 comments sorted by
View all comments
Show parent comment
3
Aren't you just binding it to the parameter inside your inner function? So instead of just adding a var, you declared a function with a parameter i to it.
This is what it compiles to:
var counter1; counter1 = (function() { return (function(i) { return function() { return i++; }; })(0); })();
2 u/rwbarton Jul 26 '13 Yes. That code is equivalent tovar 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.
2
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.
View all comments
Show parent comment
3
u/iopq Jul 26 '13
Aren't you just binding it to the parameter inside your inner function? So instead of just adding a var, you declared a function with a parameter i to it.
This is what it compiles to: