yesterday the quotes are good practice. see:
http://groups.google.com/group/jquery-en/msg/821f4eb134c51d3d (is is
just one message on a 31-long thread, if u have time ,read the whole
thread it is interesting )
As for this issue after extensive googling i found out that setTimeout
and setInterval scope the called function to the window object, not
the object the setinterval is called in.
Therefore here is how to do it:
var datascape = {
'mouseX': 0,
'myInterval': 0,
'create': function(){
var thisObj = this; //<-- store this object instance in a variable
$('#datascape').bind('mousemove', function(e)
{
this.mouseX = e.pageX;
}).bind("mouseover", function()
{
datascape.myInterval = setInterval(function() {
thisObj.move(); }, 1000); // <-- use the vairable referencing the
instance
}).bind("mouseout", function()
{
clearInterval(datascape.myInterval);
});
},
'move': function(){
$.log('datascape.move : mouseX = ' + this.mouseX);
}
}
On Thu, Jan 1, 2009 at 3:46 PM, donb <falconwatcher@comcast.net> wrote:
>
> You should change 'move' to move (remove apostrophes).
>
>
> On Jan 1, 9:01 am, "Alexandre Plennevaux" <aplennev...@gmail.com>
> wrote:
>> 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:
Post a Comment