Re: Changes in chrome JS code due to ES6 global lexical scope
I think that would fail as well, because the let would be shadowing the global x, which isn't allowed. On Sep 18, 2015 2:25 PM, "Neil" wrote: > Shu-yu Guo wrote: > > Good catch and thanks for the correction! The take-home from the example is >> that: due to the global lexical scope, a TDZ error could arise later due >> to >> newly introduced bindings. >> >> So for that I guess the code would have to look like this? > > > var x; > function f() { dump(x); } > f(); // prints undefined > > > > f(); // throws TDZ error? > let x = 42; > > > -- > Warning: May contain traces of nuts. > ___ > dev-platform mailing list > dev-platform@lists.mozilla.org > https://lists.mozilla.org/listinfo/dev-platform > ___ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform
Re: Changes in chrome JS code due to ES6 global lexical scope
On 17/09/15 19:59, Shu-yu Guo wrote: > Because until now, our global 'let' semantics have been identical to > those of 'var', I have already landed a patch that mass replaces global > 'let' with 'var' as part of bug 1202902. I think someone should make you a "var is the new let" t-shirt... Gerv ___ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform
Re: Changes in chrome JS code due to ES6 global lexical scope
Shu-yu Guo wrote: Good catch and thanks for the correction! The take-home from the example is that: due to the global lexical scope, a TDZ error could arise later due to newly introduced bindings. So for that I guess the code would have to look like this? var x; function f() { dump(x); } f(); // prints undefined f(); // throws TDZ error? let x = 42; -- Warning: May contain traces of nuts. ___ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform
Re: Changes in chrome JS code due to ES6 global lexical scope
Good catch and thanks for the correction! The take-home from the example is that: due to the global lexical scope, a TDZ error could arise later due to newly introduced bindings. On Thu, Sep 17, 2015 at 7:34 PM, Boris Zbarsky wrote: > On 9/17/15 8:26 PM, Shu-yu Guo wrote: > >> The first call to f() does not throw. >> > > It actually does, because the bareword lookup for "x" fails. You get > "ReferenceError: x is not defined". > > If you replaced "x" with "window.x" or "self.x" or "this.x" or something I > think you'd get the behavior you describe. > > -Boris > > ___ > dev-platform mailing list > dev-platform@lists.mozilla.org > https://lists.mozilla.org/listinfo/dev-platform > -- shu ___ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform
Re: Changes in chrome JS code due to ES6 global lexical scope
On 9/17/15 8:26 PM, Shu-yu Guo wrote: The first call to f() does not throw. It actually does, because the bareword lookup for "x" fails. You get "ReferenceError: x is not defined". If you replaced "x" with "window.x" or "self.x" or "this.x" or something I think you'd get the behavior you describe. -Boris ___ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform
Re: Changes in chrome JS code due to ES6 global lexical scope
(Isn't that bananas, by the way?) On Thu, Sep 17, 2015 at 5:26 PM, Shu-yu Guo wrote: > On Thu, Sep 17, 2015 at 5:18 PM, Neil wrote: > >> Shu-yu Guo wrote: >> >> 4. The global lexical scope is extensible. This means dynamic scope >>> (lol!): >>> >>> >>> function f() { dump(x); } >>> f(); // prints undefined >>> >>> >>> >>> let x = 42; >>> f(); // prints 42 >>> >>> >>> Would you mind clarifying what this is supposed to demonstrate? It looks >> to me that this is demonstrating TDZ semantics, and under ES6 the first >> call to f() will throw. >> > > The first call to f() does not throw. These are two separate > tags, and during the execution of the first