A bit confused by B.3.2 - Web Legacy Compatibility for Block-Level Function Declarations
Allen Wirfs-Brock
allen at wirfs-brock.com
Mon Jun 2 09:37:51 PDT 2014
On Jun 2, 2014, at 6:12 PM, John Lenz <concavelenz at gmail.com> wrote:
>
>
> It seems to imply that existing "sloppy" code that does this is block scope:
>
> for (let x = 1; x < 1; x++) {
> function f() {
> }
> store(f);
> }
>
The above can't be “legacy code” as it contains a “let”. But, I’ll assume you meant to use a “var” in place of the “let”.
> But this is not (as there is a second definition of f):
>
> for (let x = ; x < 10; x++) {
> for (let y = 1; x < 10; x++) {
> function f() {
> }
> store(f);
> }
> for (let y = 1; x < 10; x++) {
> function f() {
> }
> store(f);
> }
> }
>
> Is this what is intended?
Yes, we are only defining a meaning of the code that falls into the interoperable semantic intersection of legacy browser Es implementations. Your example does not work interoperability across all legacy browsers. The reason is that some browsers apply the same inner function hoisting and initialization rules across an entire function body, include nested blocks. So, in your second example, the second f declaration would be the definition that is initialized on entry to the outer function and used for all references to f. Other browsers didn’t do this. So this code is not interoperable and ES6 does not try to preserve any legacy semantics for it.
Allen
More information about the es-discuss
mailing list