A few arrow function specification issues
dherman at mozilla.com
Mon Apr 23 14:45:35 PDT 2012
On Apr 21, 2012, at 1:38 PM, Angus Croll wrote:
> >>a function shouldn’t work radically (and silently!) different depending on how it is invoked
> every current JS function behaves exactly this way :-)
No, not at all. What Axel is saying is that you're proposing a new distinction that *does not exist* in JS. You cannot distinguish whether a function was called as a method, as a function, or via .call/.apply. There's no way to tell. All you have is the receiver value bound to `this`, however it was passed in. Your function can decide whether or not to disregard the receiver entirely, but it can't tell where it came from.
The caller has the freedom to choose how it *provides* the receiver:
obj.m = f; obj.m()
but the callee can't tell the difference between f.call(null) and f().
> I'm painfully aware that I sound like a broken record on this, but introducing a hard-bound function option while continuing to suport dynamic-bound functions everywhere else is not going to simplify anything. Another function should not need to know how its function arguments were created in order to work properly - thats a terrible anti-functional anti-pattern!
Put differently: the lexical `this` syntax is a convenient way to create a non-method function, a function that ignores its receiver.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss