Take a look at the small chunk of code here: http://pastie.caboo.se/82517 Within the onSuccess method of the Ajax.Request object I have: if (this.is_approved(transport.responseText)) is_approved is a method of the Article object. How to I bind onSuccess to the Article object? Thanks for the help! Greg --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Try onSuccess: function (t) { /* ... */ }.bind(this) TAG On Jul 26, 2007, at 10:25 AM, gmacgregor wrote:> > Take a look at the small chunk of code here: > > http://pastie.caboo.se/82517 > > Within the onSuccess method of the Ajax.Request object I have: > > if (this.is_approved(transport.responseText)) > > is_approved is a method of the Article object. How to I bind onSuccess > to the Article object? Thanks for the help! > > Greg > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Have you tried using the bind() and/or bindAsEventListener() functions that prototype provides? Assuming the instance of the Article object is named "article" then something like this should work: onSuccess: function() { ... }.bind(article); - Dash - gmacgregor wrote:> Take a look at the small chunk of code here: > > http://pastie.caboo.se/82517 > > Within the onSuccess method of the Ajax.Request object I have: > > if (this.is_approved(transport.responseText)) > > is_approved is a method of the Article object. How to I bind onSuccess > to the Article object? Thanks for the help! > > Greg > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Curses! Beaten again... - Dash - Tom Gregory wrote:> Try > onSuccess: function (t) { /* ... */ }.bind(this) > > > TAG > > On Jul 26, 2007, at 10:25 AM, gmacgregor wrote: > > >> Take a look at the small chunk of code here: >> >> http://pastie.caboo.se/82517 >> >> Within the onSuccess method of the Ajax.Request object I have: >> >> if (this.is_approved(transport.responseText)) >> >> is_approved is a method of the Article object. How to I bind onSuccess >> to the Article object? Thanks for the help! >> >> Greg >> >> >> > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 26, 12:40 pm, David Dashifen Kees <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Tom Gregory wrote: > > Try > > onSuccess: function (t) { /* ... */ }.bind(this)Bah!! I tried all sorts of variations with bind(). For example: recommend : function() { var url = this.recommend_button.href; new Ajax.Request(url, { method: ''get'', onSuccess: function(transport) { if (this.is_approved(transport.responseText)) { console.log(''cool''); } else { console.log(''uncool''); } }.bind(this); }); return false; }, ^^ that implementation threw an error in Firefox. After removing the ; after bind() everything works fine. Thanks for the help! Greg --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
<chuckle> Yeah, the semicolon would get you in trouble there. Glad you got it working. TAG On Jul 26, 2007, at 11:51 AM, gmacgregor wrote:> On Jul 26, 12:40 pm, David Dashifen Kees <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Tom Gregory wrote: >>> Try >>> onSuccess: function (t) { /* ... */ }.bind(this) > > Bah!! I tried all sorts of variations with bind(). For example: > > recommend : function() { > var url = this.recommend_button.href; > new Ajax.Request(url, { > method: ''get'', > onSuccess: function(transport) { > //... > }.bind(this); > }); > return false; > }, > > ^^ that implementation threw an error in Firefox. After removing the ; > after bind() everything works fine. Thanks for the help! > > Greg--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I consider it bad form to bind to an anonymous function, it works and it gets the job done, but i think its semantically hideous and also impairs performance. I''ve seen this a lot on ajax response handlers and event handlers, people will bind a method and send it to the function on the spot. This has a serious draw back for event handlers, you can''t remove them! Think about it you need the exact reference of what you sent it, which is now a function closure that you don''t have a reference to. The draw back for ajax requests is that it must bind it everytime the request is sent. Instead create the closure ahead of time and have it ready whenever you need it. A common thing for me to use for a click handle... this.clickHandle = this.handleClick.bind(this); On Jul 26, 2:15 pm, Tom Gregory <t...-PGZyUNKar/Q@public.gmane.org> wrote:> <chuckle> Yeah, the semicolon would get you in trouble there. > > Glad you got it working. > > TAG > > On Jul 26, 2007, at 11:51 AM, gmacgregor wrote: > > > On Jul 26, 12:40 pm, David Dashifen Kees <dashi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Tom Gregory wrote: > >>> Try > >>> onSuccess: function (t) { /* ... */ }.bind(this) > > > Bah!! I tried all sorts of variations with bind(). For example: > > > recommend : function() { > > var url = this.recommend_button.href; > > new Ajax.Request(url, { > > method: ''get'', > > onSuccess: function(transport) { > > //... > > }.bind(this); > > }); > > return false; > > }, > > > ^^ that implementation threw an error in Firefox. After removing the ; > > after bind() everything works fine. Thanks for the help! > > > Greg--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---