Function.prototype.bind

Mark S. Miller erights at google.com
Tue Sep 9 23:09:49 PDT 2008


On Tue, Sep 9, 2008 at 9:51 PM, Brendan Eich <brendan at mozilla.org> 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:

function logCall(thisVal, meth, args) {
    log('applying ' + meth + ' to ' + args + ' with ' + thisVal);
    return func.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.

-- 
    Cheers,
    --MarkM


More information about the Es-discuss mailing list