Mark S. Miller wrote:
> On Tue, Sep 9, 2008 at 9:51 PM, Brendan Eich <[EMAIL PROTECTED]> wrote:
>>> I have also assumed the existence of a "static" Function.apply which
>>> takes the function to be applied as an explicit first argument.
>> This was part of ES4 and it's in JS1.7+ in Firefox.
> 
> Since the function constructor is itself a kind of function, this
> overloading breaks Liskov substitutability. Suppose someone defines a
> logCall function:
> 
[corrected version]
> function logCall(thisVal, meth, args) {
>    log('applying ' + meth + ' to ' + args + ' with ' + thisVal);
>    return meth.apply(thisVal, args);
> }
> 
> doing a logged call to the Function constructor
> 
>     logCall(Function, null, ['foo', 'bar', 'foo + bar'])
> 
> will do the wrong thing for no good reason.

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).

Note that apply3 and call3 are not, AFAICS, reliably expressible in
terms of Function.prototype.apply and Function.prototype.call.

-- 
David-Sarah Hopwood
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to