arrow function syntax simplified

Brendan Eich brendan at mozilla.com
Tue Mar 27 19:03:19 PDT 2012


Kevin Smith wrote:
> I like the => syntax, but I'm not convinced regarding single arrow 
> functions.

Me neither.

> Some observations:
>
> 1) A shorter function syntax for classic functions doesn't seem to 
> carry much payoff.

Only six letters.

> 2) Generally, users will want closures to have lexically-bound this. 
>  The strawman makes this possible via either do expressions ("=> do") 
> or this initializers ("(this=this, ...) -> {}"), both of which are 
> somewhat "clunky".

No, the strawman says => *always* lexically binds |this|. How was it 
unclear? I will fix it.

I'm going to cut the this=... jazz.

> Also, in my analysis, I discovered that the most common number of 
> formal parameters for arrow function candidates is one.  I think that 
> readability can be improved if we can eliminate parenthesis for this 
> common case, as in C#.
>
>     array.map((x) => x * x);
>     // vs.
>     array.map(x => x * x);

We could do this, but only for the single identifier case.

/be


More information about the es-discuss mailing list