Body-level inner function declarations interaction with the let "temporal dead zone"

John Lenz concavelenz at gmail.com
Sat Jul 19 14:34:10 PDT 2014


It is my understanding that in both cases the declaration are valid but
calling inner before "let x" will result in an exception.
On Jul 18, 2014 5:34 PM, "Shu-yu Guo" <shu at mozilla.com> wrote:

> Hi all,
>
> Am I correct in understanding that body-level inner functions hoist both
> declaration *and* initialization to the top of the outer function?
>
> That is, given the following snippet:
>
> Listing 1
> ---------
> function outer() {
>   let x;
>   function inner() {
>     x = 2;
>   }
> }
>
> Is it equivalent to the following?
>
> Listing 2
> ---------
> function outer() {
>   var inner = function inner() {
>     x = 2;
>   };
>   let x;
> }
>
> If so, that means in inner functions, all free uses of let-declared
> variables from outer lexical scopes are in the ES6 "temporal dead zone".
> More problematically, it means that there is no-easy-to-compute dominance
> relation (i.e., at parse time) to omit the dead zone checks for any upvar
> uses of let bindings, even though textually, listing 1 looks like the
> initialization dominates all uses.
>
> --
> shu
>
> _______________________________________________
> 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/20140719/f95bfa96/attachment.html>


More information about the es-discuss mailing list