Volunteers needed: Function.prototype.bind() in ES3.1 pseudo-code

Garrett Smith dhtmlkitchen at gmail.com
Thu Sep 18 15:32:33 PDT 2008

On Thu, Sep 18, 2008 at 11:05 AM, Mike Shaver <mike.shaver at gmail.com> wrote:
> On Thu, Sep 18, 2008 at 1:41 PM, Garrett Smith <dhtmlkitchen at gmail.com> wrote:
>> 2008/9/18 Mark S. Miller <erights at google.com>:

OK. I think I got what you're saying now. I've taken the consideration
that |arguments| may be deprecated. I also considered that it might
seem desirable to bind non-functions that implement [[Call]] (possibly
a host object).

makeDiv = Function.bind(document.createElement, document, "div");

Function.prototype.bind( context, [ preArg1 [, preArg1 [,...]]])

Returns a function that invokes this function. The |context| argument
determines the execution context of the returned function. Arguments
1..n are used for values of parameter variables to this function.

1. if this does not have a [[Call]] property, throw a TypeError
2. let FUN = this
3. if caller supplied more than one argument, go to step 6.
4. create a FunctionExpression that performs the following steps:
  4.1. Call the [[Call]] operation on FUN with the argument list
provided by the caller.
  4.2. return Result(4.1)

(as if by the statements:
  return Function.prototype.apply.call(thisFun, context, arguments);

5. return Result(4)
6. let PREARGS = a copy of the argument list provided by the caller,
starting from position 1
7. create a FunctionExpression that performs the following steps:
  7.1. Create an ArgumentList containing all of the items of PREARGS
followed by the arguments supplied by the caller.
  7.2. Call the [[Call]] operation on FUN, with Result(7.1) as the
  7.3. return Result(7.2)

(as if by the statements:
  var PREARGS = Array.prototype.slice.call(arguments, 1);
  return Function.prototype.apply.call(thisFun, context,
    Array.prototype.concat.apply(PREARGS, arguments));

8. return Result(7)

The length property of the bind method is 1.

Is this anywhere close to being what you're looking for?

> Mike

More information about the Es-discuss mailing list