WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 setInterval in an object, chris, July 10, 2003
     Re:setInterval in an object, k, July 11, 2003
         Re:setInterval in an object, Erik Arvidsson, July 11, 2003
             Re:setInterval in an object, Chris, July 13, 2003
             Re:setInterval in an object , tim scarfe, July 12, 2003
                 Re:setInterval in an object , Erik Arvidsson, July 13, 2003
             Re:setInterval in an object, k, July 11, 2003
                 Re:setInterval in an object, Erik Arvidsson, July 11, 2003

Subject: Re:setInterval in an object From: k Date: July 11, 2003
that's because when you do something like

setInterval("this.method1()",1000);

this.method1() is in fact NOT called inside (let's say it like that) the object.

exemple:

function chris()
{ ...
this.method1 = someFunction;
...
setInterval("this.method1()",1000);
}
var dummy= new chris();

will be executed somehow this way

var dummy= new chris(); // interval is set
// wait 1000ms
this.method1(); // NOT dummy.method1();
etc...

Bratta's work around is highly recommended:

function chris( id ) // unique ID needed
{ this.mySelf= "aChrisObject"+ id;
// new variable, outside the scope of the object
eval( this.mySelf +"=this" );
...
setInterval(this.mySelf +".method1()",1000);
}
var dummy= new chris(1);

will be executed somehow this way

var dummy= new chris(1); // interval is set
dummy.mySelf= 'aChrisObject1';
var aChrisObject1= dummy;
// wait 1000ms
aChrisObject1.method1(); // dummy.method1();
// wait 1000ms
aChrisObject1.method1(); // dummy.method1();


it's not really easy to understand the first time ^^



Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX