(Isn't that bananas, by the way?) On Thu, Sep 17, 2015 at 5:26 PM, Shu-yu Guo <s...@mozilla.com> wrote:
> On Thu, Sep 17, 2015 at 5:18 PM, Neil <n...@parkwaycc.co.uk> wrote: > >> Shu-yu Guo wrote: >> >> 4. The global lexical scope is extensible. This means dynamic scope >>> (lol!): >>> >>> <script> >>> function f() { dump(x); } >>> f(); // prints undefined >>> </script> >>> >>> <script> >>> let x = 42; >>> f(); // prints 42 >>> </script> >>> >>> 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 <script> > tags, and during the execution of the first <script> tag, there is no > global lexical binding named 'x', so no TDZ semantics are triggered. > Instead, undefined is printed because there is no binding named 'x' and > presumably the 'x' property on the global object is undefined. > > When we execute the second <script> tag, we now have made a global lexical > binding named 'x'. When we call f() again, it will print the value of that > binding. > > To contrast, the following two scripts would throw due to TDZ: > > <script> > function f() { dump(x); } > f(); // doesn't throw, prints undefined > </script> > > <script> > f(); // throws due to TDZ > let x; > </script> > > > The second call to f() throws because during the second script's > execution, there is an uninitialized global lexical binding 'x'. > > >> -- >> Warning: May contain traces of nuts. >> _______________________________________________ >> dev-platform mailing list >> dev-platform@lists.mozilla.org >> https://lists.mozilla.org/listinfo/dev-platform >> > > > > -- > shu > -- shu _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform