On Oct 1, 2013, at 4:35 PM, Suresh Jayabalan wrote:
> According to 14.2.1, the following arrow function expression should produce
> an early error :
>
> x => {var x;}
>
> Here is the spec line that mandates this rule. While this scenario is allowed
> in the regular functions (even in strict mode), I would like to understand
> the rationale behind this specific rule in arrow functions. Can someone shed
> some light on this ?
>
> -------
> 14.2.1Static Semantics: Early Errors
> ArrowFunction : ArrowParameters => ConciseBody
> · It is a Syntax Error if any element of the BoundNames of
> ArrowParameters also occurs in theVarDeclaredNames of ConciseBody.
> · It is a Syntax Error if any element of the BoundNames of
> ArrowParameters also occurs in the LexicallyDeclaredNames of ConciseBody.
> -------
The basic idea was that the parameters and body scope of a function are treated
as a single "name space" where duplicate definitions are not allowed. Except
that multiple var (and function) definitions are not considered duplicate
definitions. For example:
function () {
let x;
var x; //illegal redefinition
}
function (x) {
let x; //illegal redefinition
}
function () {
var x;
var x;// allowed
}
function (x) {
var x; //allowed
}
Regular function formal parameter bindings are considered to be var-like and
hence only the LexciallyDeclaredNames (let-like) restriction applies to them.
The VarDeclaredNames restriction is there for ArrayParameters based upopn the
understanding that they were going to be considered let-like declarations.
But, this might all change as we try to get final consensus on parameter
scoping and ArrayParameter semantics
Allen
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss