Thursday, January 1, 2009

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

Hello mates,

i have an object datascape which among other things, contains a
property storing the mouse position, and a function that uses that
property. Inside another method i

var datascape = {
'mouseX': 0,
'myInterval': 0,
'create': function(){
$('#datascape').bind('mousemove', function(e)
{
this.mouseX = e.pageX;
}).bind("mouseover", function()
{
this.myInterval = setInterval(this.move, 200);

}).bind("mouseout", function()
{
clearInterval(this.myInterval);
});
},

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

Yet the script does not work:
firebug console points at the setInterval call, saying:

useless setInterval call (missing quotes around argument?)
http://localhost/prototype/_js/frontend/proto.03.js
Line 172

can someone help me / explain what i'm doing wrong ?

Thank you,

Alexandre

PS: to all jquerians: happy 2009 !!

No comments: