Draft of Function.prototype.bind.

Mark S. Miller erights at google.com
Fri Oct 31 20:08:09 PDT 2008


With the formatting from the word doc, as converted by other tools:
*15.3.4.5 Function.prototype.bind (thisArg [, arg1 [, arg2, …]])*

The bind method takes one or more arguments, *thisArg * and (optionally) *
arg1*, *arg2*, etc, and returns a new function object by performing the
following steps:

   1. Let *T* be *thisArg*.
      2. Let *G* be the *this* object.
      3. If IsCallable(*G*) is *false*, throw a *TypeError* exception.
      4. Let *A* be a new (possibly empty) internal list of all of the
      argument values provided after *thisArg* (*arg1*, *arg2* etc), in
      order.
      5. Create a new native ECMAScript object and let *F* be that object.
      6. Set the [[Class]] property of *F* to *"Function".*
      7. Set the [[Prototype]] property of *F* to the original Function
      prototype object as specified in 15.3.3.1.
      8. Set the [[Call]] property of *F* as described in 15.3.4.5.1.
      9. Set the [[Construct]] property of *F* as described in 15.3.4.5.2.
      10. The [[Scope]] property of *F* has no observable effect, and so can
      be ignored.
      11. If the [[Class]] property of *G* is *"Function"*, then
         1. Get the *length* property of *G*.
         2. Let *L* be Result(11a) minus the length of *A*.
         3. Set the *length* property of *F* to either 0 or *L*, whichever
         is larger.
      12. Else set the *length* property of *F* to 0.
      13. The *length* property of *F* is given attributes as specified in
      15.3.5.1.
      14. Set the [[Extensible]] property of *F *to *true*.
      15. If the [[Class]] property of *G* is *"Function"*, then
         1. Get the *prototype* property of *G*
         2. Set the *prototype* property of *F* to Result(15a).
      16. Else
         1. Create a new object as would be constructed by the expression *new
         Object()*where *Object* is the standard built-in constructor with
         that name.
         2. Set the *constructor* property of Result(16a) to *F*. This
         property has attributes { [[Writable]]: *true*, [[Enumerable]]: *
         false*, [[Configurable]]: *true* }.
         3. Set the *prototype* property of *F* to Result(16a).
      17. The *prototype* property of *F* is given attributes as specified
      in 15.3.5.2.
      18. Return *F*.

*15.3.4.5.1  [[Call]]*

Algorithm for the [[Call]] method of a function *F* returned from the
*bind*method:

When executed with zero or more arguments, *F* uses the values of *T*, *G*and
*A* that were associated with it at its creation, and the following steps
are taken:

   1. Let *Args* be a new internal list containing the same values as the
      list *A* in the same order followed by the argument list passed
to *F*in the same order.
      2. Invoke the [[Call]] method of *F* providing *T* as the *this* value
      and providing *Args* as the arguments.
      3. Return Result(3).

*15.3.4.5.2  [[Construct]]*

Algorithm for the [[Construct]] method of a function *F* returned from the *
bind* method:

When executed with zero or more arguments, *F* uses the values of *G* and *A
* that were associated with it at its creation, and the following steps are
taken:

   1. If *G* has no [[Construct]] method, a *TypeError* exception is thrown.
      2. Let *Args* be a new internal list containing the same values as the
      list *A* in the same order followed by the argument list passed
to *F*in the same order.
      3. Invoke the [[Construct]] method of *F* providing *undefined* as the
      *this* value and providing *Args* as the arguments.
      4. Return Result(3).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20081031/bc59d831/attachment.html>


More information about the Es-discuss mailing list