Arrow binding

David Herman dherman at mozilla.com
Tue Apr 24 13:40:51 PDT 2012


On Apr 24, 2012, at 10:03 AM, Tab Atkins Jr. wrote:

> There doesn't seem to be a need there for thin-arrow (dynamic this) functions.
> 
> (Edit: Oh, I see, leaning on the completion value of thin-arrow
> functions here lets you shave a few characters off.  The readability
> loss of mixing the two syntaxes doesn't seem worthwhile, though.)

Lets you eliminate "{" and "}" and "return", but requires additional ":" and "->". Net savings of 3 characters. But more than that, eliminating "return" lets you write methods in a functional style without needing the explicit control flow operator.

> The only case that isn't receiving special syntax (and thus which
> could potentially benefit from a dynamic-this thin-arrow function) is
> #3.  However, while #3 is common today, #1 and #2 will eat most of its
> share.  I'm not sure that the remaining #3 cases will be worth a
> special syntax.

Classes certainly make it less necessary, given that cases like:

    C.prototype.m1 = function(...) { ... };
    C.prototype.m2 = function(...) { ... };
    C.prototype.m3 = function(...) { ... };

will often be replaced by classes. But I am less sure it'll go away.

> If they are, though, nothing's closing the door on a thin-arrow in the
> future.  No reason to block fat-arrow based on this.

I'm definitely not advocating blocking fat-arrow! I favor both of them, though IMO fat-arrow is more important.

Dave



More information about the es-discuss mailing list