Re:Redline Smalltalk V1.0
by jerf on Monday November 26, 2012 @12:30PM
(#4832889)
Paste this into your browser location bar (it won't navigate away):
That var a doesn't declare a new var within its scope, it declares it in the function, plus it is counterintuitive how that var a "retroactively" makes that local scope. Javascript has lexical scoping, but only within functions, not within all the scopes other languages have.
[ Parent
| on HN ]
You want block scoping. Block scoping is coming in ES6 with the let keyword.
Python is the same here, for example, any many other languages too. Making `a` a local variable here is rather ugly thing to do, but it's (somewhat) consistent with how `function` keyword (not an expression) works.
The point being: JS implements full and proper lexical scoping; implementing lexical scoping for every block is not a requirement for having lexical scoping.