I'm trying to wrap my head around the new standardized block-level functions in ES6 by reading the raw spec. My superficial understanding was:
- Block-level functions declarations are allowed in ES6.
- They hoist to the top of the block.
- In strict mode, they aren't visible outside the containing block.
However, this is further complicated by the fact that part of these semantics are specified to be "optional" and only mandatory for web browsers (Annex B). So I would like have the following table filled:
| Visible outside of block? | Hoisted? Up to which point? | "TDZ"? | ------------------------------------------------------------------------------------------------------------------------ | Non-strict mode, no "web extensions" | | | | | Strict mode, no "web extensions" | | | | | Non strict mode, with "web extensions | | | | | Strict mode, with "web extensions" | | | |
Also it is unclear to me what "strict mode" means in this context. This distinction seems to be introduced in Annex B3.3, as part of some additional steps for the runtime execution of a function declaration:
1. If strict is false, then
...
However, as far as I can see, strict
refers to the [[Strict]]
internal slot of the function object. Does this mean that:
// Non-strict surrounding code
{
function foo() {"use strict";}
}
should be considered "strict mode" in the table above? However, that's contradicts my initial intuition.
Please, bear in mind that I'm mostly interested in the ES6 spec itself, regardless of actual implementation inconsistencies.