Global lexical tier

saam barati saambarati1 at gmail.com
Mon Aug 31 20:43:47 UTC 2015


I think a better solution would have been to have all top-level
let/const/class
variables just be local to that specific Program. That's how I originally
implemented it in JavaScriptCore, and now I'm going back and "fixing"
it to be as it is defined in the Spec.
(That said, I agree that allowing these to be global properties is better
than how it's currently defined.)

Saam

On Mon, Aug 31, 2015 at 9:08 AM, Jason Orendorff <jason.orendorff at gmail.com>
wrote:

> Hi everyone. Can we talk about the global lexical tier?
>
> This was a mistake, a real blunder. We all should have known better.
> An extensible intermediate scope implies dynamic scoping. The referent
> of an identifier can change only once, but it can change. It's like an
> implicit `with` block around *all code*.
>
> This pattern for declaring variable in multiple scripts won't work
> with let/const:
>
>     var MyES3Module = MyES3Module || {};
>
> There's no workaround except "keep using var".
>
> It's now possible to get a binding permanently wedged, which is bad for a
> REPL:
>
>     js> let z = Maht.PI;  // oops, typo
>     ReferenceError: Maht is not defined
>     js> z
>     ReferenceError: binding is not initialized: "z"
>     js> z = 1;
>     ReferenceError: binding is not initialized: "z"
>     js> delete z;
>     false
>     js> let z = 1;
>     SyntaxError: redeclaration of variable: "z"
>
> For a single name to have two global bindings, both mutable, is
> astonishing.
>
> All of this was unnecessary. What's the benefit to users? We ran
> roughshod over existing practice, invariants, and expectations in
> order to obtain a kind of self-consistency for `let` that users don't
> expect or even care about.
>
> We should have just made toplevel let/const/class create global
> properties, like var. This is how it was proposed originally and how
> Babel implements it today. For SpiderMonkey, switching to the worse,
> less user-friendly way without regressing performance is
> time-consuming.
>
> We knew all this. We didn't evaluate it correctly. What we
> particularly missed is that we already had modules as the way forward
> to a nice toplevel lexical tier, and weird half measures for scripts
> were pointless.
>
> -j
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150831/04da3055/attachment.html>


More information about the es-discuss mailing list