block scope and function declarations
Allen Wirfs-Brock
allen at wirfs-brock.com
Wed Feb 15 09:10:09 PST 2012
On Feb 15, 2012, at 6:14 AM, Andy Wingo wrote:
> On Wed, 2012-02-15 at 12:55 +0100, Andy Wingo wrote:
>
>> function f(x) {
>> bar(); // ???
>> for (let y of x) {
>> function bar() { ... y ... }
>> bar(); // OK
>> }
>> bar(); // ???
>> }
>
> Did I just get wtfjs'd here? Is this `bar' not a source element, and
> therefore this is a function expression and not a declaration?
No, in ES5 and earlier the above is not syntactically valid code, blocks contains StatementLists rather than SourceElements and FunctionDeclaration can not occur in StatementLists. Nor can a ExpressionStatement begin with an unparenthesized FunctionExpression. Even ignoring the let, there is no valid interpratation of the above in unextended ES5.
In ES6, FunctionDeclarations are allowed in StatementLists
>
> Sheepishly yours,
>
> Andy
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
More information about the es-discuss
mailing list