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

Shu-yu Guo shu at mozilla.com
Fri Jul 18 17:34:18 PDT 2014


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



More information about the es-discuss mailing list