What is the evaluation context of the setTimeout args below? I have a
separate Timer instance for each sprite in my program. As coded,
"this.Clock " doesn't work. Thanks ahead for any advice.
Albert
/*============== =============== =============== ========
Timer.js
=============== =============== =============== =======*/
function Timer(_sprite, _interval) {
var sprite = _sprite;
var interval = _interval;
var isRunning = false;
var timeoutID = false;
this.Clock = function() { // called after setTimout interval
if (isRunning) {
isRunning = sprite.OnClockT ick();
if (isRunning)
timeoutID = window.setTimeo ut("this.Clock( )", interval);
else
this.Stop();
}
}
this.Stop = function() {
if (timeoutID) {
window.clearTim eout(timeoutID) ;
timeoutID = false;
};
isRunning = false;
}
this.SetInterva l = function(_inter val) {
this.Stop();
interval = _interval;
isRunning = true;
timeoutID = window.setTimeo ut("this.Clock( )",interval) ;
}
this.Continue = function() {
if (!isRunning) {
isRunning = true;
timeoutID = window.setTimeo ut("this.Clock( )",interval) ;
}
}
}
--
Don't you see that the whole aim of Newspeak is to narrow the range of
thought? In the end we shall make thoughtcrime literally impossible,
because there will be no words in which to express it.
-- George Orwell, 1984
Comment