arrow function syntax simplified

Brendan Eich brendan at mozilla.com
Wed Mar 28 13:46:21 PDT 2012


Kevin Smith wrote:
>
>     I hate the CoffeeScript deviation, though. It's just confusing for
>     anyone who ever learned that fat-arrow binds |this| and thin-arrow
>     doesn't.
>
>
> True.  On the other hand, "all arrows bind |this|" is also quite 
> simple and easy to remember.

Yes, and I kept the part of the proposal that allows |this| as a leading 
arrow formal parameter, including with parameter default value. This 
suggests a slight variation on the strawman, per your suggestion:

x -> { return this.x; } // lexical this for thin arrow
x => this.x // as for fat arrow

(this, x) -> { return this.x; } // dynamic this, five letter syn-tax
(this, x) => this.x // ditto for the expression-body form

IOW we make fairly concise, orthogonal syntactic tools for composing (a) 
lexical vs. bound |this|, and (b) block vs. expression (including object 
literal) body.

(I used your suggestion of the C#-like shorthand for 
single-formal-parameter above -- nice!)

/be


More information about the es-discuss mailing list