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

John Lenz concavelenz at gmail.com
Wed Jun 4 14:43:14 PDT 2014

On Wed, Jun 4, 2014 at 7:59 AM, Allen Wirfs-Brock <allen at wirfs-brock.com>

> On Jun 3, 2014, at 3:12 PM, John Lenz <concavelenz at gmail.com> wrote:
> 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.
> OK, I see.  No, the presence of “let” etc. doesn’t change anything.
>  However, hopefully anybody using such new features will not depend upon
> anything other than pure block scoping and not write new code that depends
> upon the legacy compatibility semantics.   Linters should flag code that
> depends upon the legacy semantics.  Note that
> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-web-legacy-compatibility-for-block-level-function-declarations says
> that ES implementations should log warnings when encountering such code.

How does someone write code to make sure it doesn't fall into legacy
semantics?  Unless, I misunderstand these rules seem like a refactoring
hazard.  It would seem better to say: sloppy mode === no block scoped
function declarations.  strict mode === block scoped function declarations.

It seems like the most important case is a block scoped function used in a
loop or otherwise capture block scoped values.    Couldn't the sloppy mode
rule be a function declaration is block scoped if it captures a block
scoped value?

> Also, note that block scoping applies to all ES6 block level function
> declarations, in both strict and “sloppy” mode. The only difference is that
> in sloppy mode, in addition to the creation of the block level bindings of
> the function name, there is also a binding for the same name created
> (unless certain error conditions exist) at the top level of the function.
>  That extra binding is only initialized (i.e., can be referenced without
> error) after a corresponding block level function declaration has been
> dynamically evaluated).
> Code that uses uses block level functions and don’t depend upon the legacy
> semantics will produce the same results in either strict or sloppy mode.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140604/6bf9309c/attachment-0001.html>

More information about the es-discuss mailing list