On 30 September 2014 22:38, David Herman <[email protected]> wrote: > On Sep 30, 2014, at 4:03 AM, Andreas Rossberg <[email protected]> wrote: > >> On 30 September 2014 12:52, Jason Orendorff <[email protected]> >> wrote: >>> I just realized this has an unfortunate implication for REPLs. Suppose >>> you make this typo: >>> >>> js> let x = Math.cso(a) // oops, TypeError, should be Math.cos >>> >>> Now x is irreparably hosed in your REPL. That seems bad. >> >> No surprise. One of the reasons why I always favoured a nested scopes >> model for multiple scripts... > > We've had this debate a million times, but for anyone who's unfamiliar with > the arguments: nested scopes makes recursive bindings across scripts > impossible and is also hard to understand with things like asynchronous > script execution order (such as <script async>). And it's totally different > from the existing mental model of global code.
Well, to reiterate: - Cross-script recursion via declarations does not work in strict mode anyway, so is not a solution moving forward. - Nothing is easier about async scripts in a mutable scope model -- you just trade unpredictable shadowing for unpredictable overwrites. It's hard to argue that the latter is better by any reasonable metric. > But since we're rehashing, this is an example of why *I've* always thought > new binding forms should just go in the global object just like vars and > functions do. JS's global scope is extremely complex and subtle, and you > can't undo that complexity by adding additional layers. And the metal model, > while unfortunate, already occupies programmers' brainspace -- adding an > extra layer of scope for some binding forms makes the mental model more > complex. For the record, nobody has ever come up with an acceptable explanation for realising TDZ directly on the global object without breaking (or grossly extending) the object model. And TDZ is required, at least for const bindings, to be self-consistent. (I suggested an explanation at one point: installing lexical bindings as getters/setters on the global object, mirroring what happens with module instance objects. But that was considered too complicated.) > We basically have the following set of constraints that various people have > tossed into the mixing bowl. It seems no matter which way you mix it, at > least one of the constraints falls back out of the bowl: > > 1. Make `let` mean the same thing at top-level that it means locally. > 2. Enable recursive bindings across multiple scripts. > 3. Avoid the spec/design work of reifying new binding forms' reification in > the global object. > 4. Preserve the mental model of the global object. > > Note that, as so often happens, we have one dimension of consistency (scoping > semantics of `let` in local vs. global contexts) in tension with another > dimension of consistency (globals going in the global object vs. globals > going in a new scope layer). You forgot that other dimension of consistency that I mention above, which was the real road block. In the light of that, there was a clear lesser evil, which is what we chose. /Andreas _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

