arrow function syntax simplified

Kevin Smith khs4473 at gmail.com
Tue Mar 27 18:54:00 PDT 2012


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

Some observations:

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

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".  This would seem to make a large portion (perhaps even a slight
majority) of candidates for this syntax pay a "clunk" tax.

This would seem to indicate that -> functions should have lexically-bound
this.

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);

kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120327/36689a8b/attachment.html>


More information about the es-discuss mailing list