Function.prototype.bind

David-Sarah Hopwood david.hopwood at industrial-designers.co.uk
Wed Sep 10 18:33:29 PDT 2008


Garrett Smith wrote:
> On Wed, Sep 10, 2008 at 3:41 PM, David-Sarah Hopwood
> <david.hopwood at industrial-designers.co.uk> wrote:
>> Mark S. Miller wrote:
>>> On Tue, Sep 9, 2008 at 9:51 PM, Brendan Eich <brendan at mozilla.org> wrote:
> 
>> This can be fixed by either renaming Function.apply, or conditioning
>> on whether there are two or three arguments (the former is more elegant).
>> The important point is the need for a static 3-argument version of
>> 'apply', not what it is called. I will suggest the name 'apply3' as
>> a starting point (for symmetry and convenience 'call3' should also be
>> provided).
> 
> Why would "Function.apply3" need three arguments?

Because Function.prototype.apply takes two arguments, and apply3
(or staticApply, or whatever it is called) makes the 'this' argument
explicit.

> Function.prototype.apply doesn't actually need any arguments.

No, it always takes two arguments, which may be undefined. But since
an undefined argument can't be distinguished from a missing one, that
does mean it's not possible to condition on whether there are two or
three arguments. (Besides, I withdrew the suggested name 'apply3'.)

> See for yourself:-
> 
> function fun(){ alert(42); }
> Function.prototype.apply.call(fun);

This is equivalent to
  Function.prototype.apply.call(fun, undefined, undefined);

-- 
David-Sarah Hopwood


More information about the Es-discuss mailing list