Re:Redline Smalltalk V1.0
by klibertp on Monday November 26, 2012 @12:11PM
(#4832815)
JS has no "proper lexical scoping"? How so? I'm really curious... what your definition of "proper" is here, because JS definitely has lexical scoping.
[ Parent
| on HN ]
Paste this into your browser location bar (it won't navigate away):
javascript:void(function(){a = 1; {var a = 2;} alert(a)}())
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.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.