r/programming • u/zumpiez • Dec 22 '11
The Problem with Implicit Scoping in CoffeeScript
http://lucumr.pocoo.org/2011/12/22/implicit-scoping-in-coffeescript/
83
Upvotes
r/programming • u/zumpiez • Dec 22 '11
View all comments
Show parent comment
1
u/jashkenas Dec 23 '11
Ok -- so let's pursue this alternative method to forbid shadowing...
Unfortunately, Python's nonlocal keyword doesn't work so well in JavaScript, because anonymous inner functions are fairly ubiquitous in JavaScript. Even something as simple as this would have to use "nonlocal":
... or would you have to use "nonlocal" to even refer to variables outside of the current scope, making it:
... that's a pretty brutal cost. If nonlocal was required for modification, but not for reference, that would be awfully inconsistent, no? Perhaps the original suggestion for two different operators, one for "declare-and-assign", and one for "mutate", would be more palatable.