Thursday, January 1, 2009

[jQuery] Re: setInterval(obj.method,200) problem: scoping?

Whoops, I missed the original issue, which was that setInterval needs
to be told its this object.

So change this:

this.interval = setInterval(function(){
$.log('datascape.move : mouseX = ' + this.mouseX);
}, 1000);

to this:

var self = this;
this.interval = setInterval(function(){
$.log('datascape.move : mouseX = ' + self.mouseX);
}, 1000);

No comments: