You need to "bind" the actual callback function (since it will be executed in a global context otherwise): ... onSuccess: function(data) { // do some processing... this.callback(); // <= "bind" ensured that "this" refers to your instance }.bind(this) ...
- kangax On Mar 23, 7:20 pm, dj <[EMAIL PROTECTED]> wrote: > Ahhh thank you for your answer. It really saved me. > Where can I read some detailed documentation regarding "this" keyword > and how to use it correctly with prototypejs? > > I have one more question regarding this (I'll keep the same example): > > var SuperClass = Class.create(); > SuperClass.prototype = { > test : "Test data is ", > initialize : function(){ > this.doRequest(); > }, > doRequest : function() { > new Ajax.Request('somedata.php', { > method: 'get', > onSuccess : > this.callback.bind(this) <<== **here** > } ); > }, > callback : function(data) { > alert(this.test+":"+data); > } > > }; > > if I want to have instead of this.callback.bind(this) implemented > function which calls callback (only when needed) for example: > > var SuperClass = Class.create(); > SuperClass.prototype = { > test : "Test data is ", > initialize : function(){ > this.doRequest(); > }, > doRequest : function() { > new Ajax.Request('somedata.php', { > method: 'get', > onSuccess : > function(data) { do some processing; . . . ** > this.callback.bind(this); how to call callback from here ** } > } ); > }, > callback : function(data) { > alert(this.test+":"+data); > } > > }; > > Thank you. > D. > > On Mar 23, 12:43 am, jdalton <[EMAIL PROTECTED]> wrote: > > > You need to bind this.callback(); > > because its loosing the proper scope of > > "this".http://www.prototypejs.org/api/function/bind > > > this.callback.bind(this) --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---