A bit confused by B.3.2 - Web Legacy Compatibility for Block-Level Function Declarations

John Lenz concavelenz at gmail.com
Tue Jun 3 15:12:31 PDT 2014


On Mon, Jun 2, 2014 at 9:37 AM, Allen Wirfs-Brock <allen at wirfs-brock.com>
wrote:

>
> 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”.
>

No I intentionally used "let".  This is not legacy code (I shouldn't have
use the word "existing") but new "sloppy" mode code that would like the
code to be block scoped. Does a "let", "const", or "class" declaration in
scope force the function to be block scoped?  That would be great but I
think I am missing how this is specified in the spec as that would prevent
most of the ambiguity.  My main concern is code written with the intent to
be block scoped but is not due to being run in sloppy mode.

Or where the behavior changes due to a becoming block scoped (I have a
harder time coming up with a scenario where this is the case).


>
> > 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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140603/c41a01c6/attachment.html>


More information about the es-discuss mailing list