I need to access this
from my setInterval
handler
prefs: null,
startup : function()
{
// init prefs
...
this.intervalID = setInterval(this.retrieve_rate.bind(this), this.INTERVAL);
This would be the cleanest solution, since most of the time you actually want to switch the this context for your consecutive method calls:
Also it's easier to grasp the concept of.
// store scope reference for our delegating method
var that = this;
setInterval(function() {
// this would be changed here because of method scope,
// but we still have a reference to that
OURMETHODNAME.call(that);
}, 200);
That's not a beauty solution but it's in common usage:
var self = this;
var ajax = null;
//...
ajax.onload = function() {
self.prefs....;
}