On 2/21/06, Miller, Raul D <[EMAIL PROTECTED]> wrote:
> In other words, if a bound function is given the arguments
>   (This,A,B,C)
> the underlying method has 'this' bound to the value of This
> and the underlying method gets the arguments
>   (A,B,C,This,A,B,C)

Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}

In the bind function itself, 'this' is a Function.  The first
parameter to bind is the object that the function will eventually be
called on, so this in your bound function will be the object.  It took
a bit for me to wrap my head around this too, but it's amazing once
you understand it.

The arguments aren't duplicated.

The code is structured such that if you give bind() multiple
parameters (ie, more than just the object) those extra parameters
become parameters for your bound function.

Take a look at http://www.brainsick.com/prototype/testbind.html

Todd
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to