5 ms·
Did you miss that you can't create local variables?
by lolhackernews 11y ago
Did you miss that you can't create local variables?
- bsou 11y agoyou can if you cheat: http://coffeescript.org/#try:%0Aa%20%3D%201%0Ax%20%3D%20-%3E%20%0A%20%20%60var%20a%60%0A%20%20a%20%3D%202%0A%20%20return%20a%20%2B%202%0A%0Ax()%0Aconsole.log(a) http://coffeescript.org/#try:%0Aa%20%3D%201%0Ax%20%3D%20-%3E... (I jumped ship to babel though)
- klibertp 11y agoWHAT? You mean, you can't declare them without initialization. Oh well, you can't; it's also impossible in Python or Lua. Why is it a bad thing?
- lolhackernews 11y agoLet's not confuse matters here: in both those languages an initialization-assignment will introduce a new binding within function scopes. In CoffeeScript it will always be the parent scope's binding, which means that you must take extra care not to introduce variables used in scopes above, or below, at any given time. On the other hand, confusing both concepts is bad because it makes it harder to reason about scope, and it has been the cause of much confusion regarding closures in Python and Ruby.
- ufo 11y agoLua has perfectly sane lexical scope for its local variables. Don't mix it with Python and Coffeescript.
- klibertp 11y agoAh, true, I checked again and you're right. Too late to edit.