On Fri, Apr 15, 2011 at 3:40 PM, Dmitry A. Soshnikov <[email protected]> wrote: > On 14.04.2011 23:40, Sam Tobin-Hochstadt wrote: >> >> On Thu, Apr 14, 2011 at 3:29 PM, Dmitry A. Soshnikov >> <[email protected]> wrote: >> >>>> But these globals won't be accessible to scripts that have already been >>>> compiled; only to scripts that are subsequently compiled and evaluated, >>>> e.g. >>>> via ModuleLoader.eval. >>> >>> Which again seems as in chaise of efficiency, let's take away (a little >>> of) >>> convenience from a user. >> >> This isn't about efficiency at all! >> >> The reason that Dave and I have worked hard to make modules lexically >> scoped, of which this is a part, is so that when you look at a >> program, you can understand what it does. This is a fundamental part >> of programming, and not having a clear binding structure in your >> language makes it much harder. >> >> Sometimes, this makes your program more efficient, too, because the >> compiler understands your program better for the same reasons that you >> can understand your program more easily. But that really isn't the >> point. > > Actually, ECMAScript is already lexically scoped language (in respect of > closures). I think there's a mess with treating a possibility of creating a > binding at runtime with the dynamic scope. Dynamic scope > (http://bit.ly/hz7tT2 -- just for interested) is an early design flow in PLT > backing to Lisp invention times (where language authors have no much > experience). Perl e.g. still has both -- dynamic and static scopes. But JS > has/had lexical scope. > > Yes, `with` and `eval` (direct, non-strict) _are_ the features which brings > dynamics to the static scope of ES. And I always thought (and it seems quite > logical) that the direct lexical mapping of ids (which is the reason of > disallowing of creating of runtime bindings) is exactly to improve the > identifier resolution and technically it's the main reason. Avoiding object > to represent a scope and avoiding a scope chain consisting of these object > is the reason of providing direct map of "variable name : direct address" > which (theoretically?) is accessed in O(1).
1. The global object (which is what's originally under discussion here) also gives you "dynamic scope" for top-level variables. > window.fooish = 7 7 > fooish 7 2. Again, the reason that Dave and I have worked hard to avoid holes in the lexical scoping of identifiers in modules is for programmers to understand programs -- not for efficiency at all. I don't know what else to say to persuade you of this, but making identifier resolution fast is not "the main reason". -- sam th [email protected] _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

