That technique will not work for this case.

By default, the response element is passed in to the onComplete handler
as the first argument.  Basically, all 'bind' does it let you bind the
'this' element to the function, so when you reference this.whatever in
the function, the 'this' refers to 'this' in the scope that the event
handler was defined.  Calling bind with additional parameters does not
work as far as I know (unless something changed recently).  You can do
.bindAsEventListener to make sure the event object is passed along, in
the case of real event handlers, but that doesn't apply here.

I'm not sure why my suggestion earlier didn't work.  You should be able
to do this:

onComplete: function (theResponse) {
NamedActionResponseHandler(theResponse, theElement); }

function NamedActionResponseHandler (theResponse, theElement) {
// work your magic
}

If you are sending your ajax call inside another object and need to make
sure the response function is called on the same object, that is where
the .bind() would be useful.

Greg


> -----Original Message-----
> From: [EMAIL PROTECTED]
[mailto:rails-spinoffs-
> [EMAIL PROTECTED] On Behalf Of Erin Brewer
> Sent: Monday, April 10, 2006 3:10 PM
> To: rails-spinoffs@lists.rubyonrails.org
> Subject: [Rails-spinoffs] Re: Prototype Ajax - How to pass my own
params
> toonComplete
> 
> I like the technique you describe here, but when i try to reference
> 'theElement' in NamedActionResponseHandler() it is not defined.
> 
> I changed the onComplete def to:
>  onComplete: NamedActionResponseHandler.bind(this, theElement)
> 
> And changed the function to
>  function NamedActionResponseHandler(theResponse, theElement)
> 
> In the function I get 'theResponse' as the returned xml still, but
> 'theElement' is undefined, am i missing something?
> 
> 
> Martin Bialasinski wrote:
> > On 4/10/06, Michael Peters <[EMAIL PROTECTED]> wrote:
> >> change this function to return another function. Something like
this:
> >
> > Yes, this is also what .bind() does to form a closure without having
> > to change NamedActionResponseHandler
> >
> >> And then call it like this:
> >>   onComplete: NamedActionResponseHandler(theElement),
> >
> > onComplete: NamedActionResponseHandler.bind(this, theElement)
> >
> > theElement will now be passed as an additional argument to
> > NamedActionResponseHandler, when it is called via onComplete.
> >
> > Bye,
> >   Martin
> 
> 
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails-spinoffs mailing list
> Rails-spinoffs@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to