I have a class constructor in my script which creates a loop function. And in that loop function, I would like it to call itself through setTimeout(). It seems that this may not be possible, unless there is another way to do this, which is what my question is asking.
Is there a way to accomplish my goal?
example class:
Code:
function theGame ()
{
private:
/* ... */
public:
/* set methods */
/* get methods */
/* other methods */
this.loop ()
{
/* do stuff */
// tried all the following, one by one, not in the same block of code.
globalVarName = setTimeout ( function () { this.loop (); }, 1 );
globalVarName = setTimeout ( function () { loop (); }, 1 );
this.globalVarName = setTimeout ( function () { this.loop (); }, 1 );
globalVarName = setTimeout ( function () { loop (); }, 1 );
}
}
A while loop won't work, since it is an infinite loop and disables me from using my web browser.
I did fix my problem, by using an external function that handled the looping. But It looks out of place. And so I would like to know if there is a way to have setTimeout call a class method, inside the class the method is in.