arrow function syntax simplified
russell.leggett at gmail.com
Tue Mar 27 21:14:41 PDT 2012
On Mar 27, 2012, at 10:36 PM, Kevin Smith <khs4473 at gmail.com> wrote:
> But aren't non-BTFs rare based on your (revised and original) measurements?
> When you take out the object literal methods, that's right.
> The precise way to say it would be that ~90% of function expressions in the code I analyzed were either object literal methods or did not depend on dynamic |this|.
> That's exactly the reason I'm suggesting lexically bound |this| for "->" functions, because outside of "methods" (which already have shorter syntax, either via object literal extensions or classes), there doesn't appear to be a great need for function expressions with dynamic |this|.
I'm sure this is a bit of a tangent, but the other major related case is passing a "method" as an argument but needing to retain the correct "this". Obviously, that is what bind was meant for, but that is inconvenient when passing methods for the same reason it would be inconvenient for anonymous functions.
I guess what I'm proposing is a syntax supported version of bind that is independent of shorter function syntax entirely. Don't hold me to the syntax, because I don't think its right, its just to give you an idea.
//let say I have some object foo with a method bar that I want called as a callback
//right now I have to use bind, or wrap the call in an additional function
//also happens inside the class itself, and you'll see
//and finally, the case we're addressing now
What if we had a shorthand for bind that worked in both of these cases
//here the # acts as both a . and bind in one
//in this case, it obviously doesn't access a property, it just does a bind
//or with the new syntax
I'm guessing this idea is a stretch or possibly even suggested already and tossed out, but it came to me as a possibility and I thought I would mention it.
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss