On 4/10/06, Gregory Hill <[EMAIL PROTECTED]> wrote:
> Ah, well, that's good to know then.  I'd always wanted to do it this
> way, but when I last looked into it, it wasn't yet supported.   That was
> a while ago, though.  Thanks for the heads up.

I'm partial to this technique because I think it really demonstrates
some of the Prototype magic.  When I first found it and understood it,
I thought it was really clever.  Granted, clever generally means
harder to debug, but the code's small enough to not be intrusive.

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() closure, the extra parameters are held in args.  Then,
when the "bound" function is eventually called, the parameters to the
bound function are appended to the existing args.  Thus, you can
provide a set of known parameters to each function call.

(While I'm sure you could have groked this yourself, the explanation
might help someone else.  It's come up a couple times in the last few
days alone.)

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

Reply via email to