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
3
u/dobryak Dec 23 '11
I will try. Introducing a fresh variable name is done using binding (designated with "var" in JS, or when you have "function(x) { ... }" -- this is where "x" is a introduced in the body of the body). In JS (and CoffeeScript too), variables are not purely syntactic -- that is, they are not simply abbreviations for other expressions, but actually mutable memory cells.
Hence there is a difference between, say "var x = 1; var x = 5" and "var x = 1; x = 5" -- the former introduces "x" twice (these are different variables, the second one shadowing the first, and the first one is not going anywhere), whereas the latter introduces "x" once, and then changes it.
Of course, the difference is more pronounced when there is some code between two bindings or two assignments.
Does the above make sense to you?