Hi,
I'm having some difficulty with the periodical executer, I use it
within one of my objects and when I use 'this' it doesn't actually
reference the object. Here is the example:
Dubya.RadioHandler = Class.create();
Object.extend(Dubya.RadioHandler.prototype, {
initialize: function(element) {
element = $(element);
this.element = element;
this.songCount = 0;
this.lastResponse = '';
new PeriodicalExecuter(this.pollRadio, 2);
},
pollRadio: function(executer) {
caller = this;
new Ajax.Request('/radio/current',
{ method: 'GET',
onSuccess: function(transport) {
response = transport.responseText.strip();
if (!response.empty() && response != caller.lastResponse) {
caller.lastResponse = response;
caller.addSong(response);
}
}
});
},
addSong: function(title) {
new Insertion.Top('active_radio', '<p id=\"' + this.songCount++ +
'\">' + title + '</p>');
}
});
In the 'pollRadio' method, 'this' isn't Dubya.RadioHandler, so the
addSong method isn't available (it's undefined). I worked it around by
passing a reference to this in the PeriodicalExecuter constructor and
passing it back in the callback.
However I have no idea with the reference to 'this' isn't the right
one and there's probably a better way. Any idea? If there's no better
way, maybe passing 'this' to the PeriodicalExecuter constructor should
be the default behavior?
Thanks,
Matthieu
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---