On 2/21/06, Miller, Raul D <[EMAIL PROTECTED]> wrote: > Todd Ross wrote: > > Function.prototype.bind = function() { > > var __method = this, args = $A(arguments), object = args.shift(); > > return function() { > > return __method.apply(object, args.concat($A(arguments))); > > } > > } > ... > > The arguments aren't duplicated. > > Oh, I see. (oops) > > When 'args= $A(arguments),' is evaluated, 'arguments' is a list > which has only one element (the function in question).
Still not right. 'this' is the function (as the bind() method is being called on the Function). The first parameter (usually the only) to bind() is the /object/ to call the function on. I think you understand that, but you're just saying it wrong. func.apply(object, args) works like: object.method = func; object.method(args); delete object.method; (see JavaScript: The Definitive Guide, 4th Edition, Chapter 7.5.4) > In other words, it's equivalent to: > > Function.prototype.bind = function(object) { > var __method = this; > return function() { > return __method.apply(object, arguments); > } > } > > Or is there some reason this simpler version would not work? That would work except you miss out on the ability to specify 'default' parameters through the bind() method, although there are no instances of that inside Prototype itself. Todd _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs