Draft of Function.prototype.bind.

David-Sarah Hopwood david.hopwood at industrial-designers.co.uk
Mon Nov 3 20:14:04 PST 2008


Brendan Eich wrote:
> On Nov 3, 2008, at 7:16 PM, David-Sarah Hopwood wrote:
> 
>> It's completely trivial, but if you want a hand-wavey demo:
>>
>>  function makeHTMLCollection(underlying) {
>>    function collection(nameOrIndex) {
>>      // I think this is how MSIE behaves:
>>      return typeof nameOrIndex === 'string'
>>          ? underlying.namedItem(nameOrIndex)
>>          : underlying.item(nameOrIndex);
>>    }
>>    collection.namedItem = function(name) {
>>      return underlying.namedItem(name);
>>    }
>>    collection.item = function(index) {
>>      return underlying.index(index);
>>    }
>>
>>    // define any other non-standard methods
>>
>>    // should use a getter here if the length can change
>>    collection.length = underlying.length;
>>
>>    return collection;
>>  }
> 
> You are once again missing the point: IE and (because of IE's dominance)
> other browsers have callable host objects for which typeof does *not*
> return "function". Changing these as you sketch above is an incompatible
> change that may break real web content.
> 
> There is evidence for this, because Mozilla's regexps used to report
> typeof-type "function" and so fell into logic wanting only a function,
> not a callable host object.

The resolution of that bug is clearly nonformant to ES3 section 11.4.3,
as at least two commenters ('Ish' and Garrett Smith) pointed out.

-- 
David-Sarah Hopwood


More information about the Es-discuss mailing list