Try `window.foo`. That's usually what's done within global IIFEs, which has similar scope restrictions.
On Fri, Apr 15, 2016, 13:52 Oriol Bugzilla <[email protected]> wrote: > Consider this code: > ```html > <script> > let {foo} = null; // TypeError > </script> > <script> > // Here I want to assign some some value to foo > </script> > ``` > > The first script attempts to let-declare `foo` via a destructuring > assignment. However, `null` can't be destructured, so the assignment throws > a TypeError. > Some alternatives which would lead to the same problem are `let foo = > null.throw` and `let foo = (() => {throw;})()`. > > Then the `foo` variable is declared but uninitialized, so if in the 2nd > script I attempt to reference `foo`, it throws: > ```js > foo = 123; // ReferenceError: can't access lexical declaration `foo' > before initialization > ``` > > And `let` variables can't be redeclared: > ```js > let foo = 123; // SyntaxError: redeclaration of let foo > ``` > > Is this behaviour intended? Is there any way to take `foo` out of the TDZ, > so that I can assign values and read them? > > - Oriol > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

