Draft of Function.prototype.bind.

David-Sarah Hopwood david.hopwood at industrial-designers.co.uk
Mon Nov 3 19:16:32 PST 2008

Brendan Eich wrote:
> On Nov 3, 2008, at 11:32 AM, David-Sarah Hopwood wrote:
>> Mark S. Miller wrote:
>>> First, I'd like to thank Richard Cornford, cc'ed, who provided the
>>> earlier draft of Function.prototype.bind that grew into this one.
>>> Thanks!
>>> Below, I modified Richard's draft according to our agreements in
>>> Redmond. But I'm not happy with its complexity. If we instead specify
>>> that we test in step 3 whether the [[Class]] of G is "Function", the
>>> rest of bind() becomes much easier to specify. Should we? The only
>>> functionality lost is the ability to use bind() as a generic applied
>>> to callable non-functions. Do we care whether the built-in bind() can
>>> handle these?
>> We should consider simply outlawing callable nonfunctions in ES3.1.
> No, that is incompatible with every browser-based DOM implementation I
> know of.
>> An object that was previously a callable nonfunction in some browser,
>> can always be compatibly changed into a real function instead.
> Proof? Evidence? A hand-wavey demo?

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;

David-Sarah Hopwood

More information about the Es-discuss mailing list