Gregory Hill
2006-Apr-10 21:59 UTC
RE: Re: Prototype Ajax - How to pass my own paramsto onComplete
> Gregory, bind() does support this. It''s my preferred technique.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. Greg
Todd Ross
2006-Apr-10 22:08 UTC
Re: Re: Prototype Ajax - How to pass my own paramsto onComplete
On 4/10/06, Gregory Hill <Gregory_Hill-l9nu40+TWxQ@public.gmane.org> 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