A few arrow function specification issues

David Herman 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()
    f.apply(obj, [])

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!

There's no difference whatsoever between a function with a lexically-bound `this` and a function that completely disregards its `this` argument. This is simply a reality of JavaScript today and forever: every function has an API that indicates what it expects of its `this` argument and what it will do with it. If you write a function that ignores its `this` argument, your callers have to know that they can't change your function's behavior by passing a different `this`.

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...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120423/831351f0/attachment.html>

More information about the es-discuss mailing list