IrYoKu
12-06-2003, 12:53 PM
Hi,
I was coding a script and have come to this problem:
I have a global variable called tasks, that contain objects of prototype task -I have tried to simplify the code-
tasks = new Array();
tasks[0] = new task;
tasks[0].taskR();
function task();
{
function taskR()
{
window.setTimeOut(tasks[0].taskR, 10);
}
}
What I want is an object that contains a function that call itselft recursively every 10 ms.
I pass to setTimeOut the function I want to call (not an expresion, the omission of the quotation marks is intentional), but the script don't work because it seems (this is my own theory) that the tasks[0].taskR called by setTimeOut is not the taskR that contain tasks[0]. It is treated as another function (maybe contained in the global scope of the script) and I don't understand very well this behaviour. If you try this script it will hang your navigator and probably your os (if Windows).
I know there are an easy work around to this, but I would like to know why this script is not working to get a better understanding of the javascript objects.
This page (http://www.faqts.com/knowledge_base/view.phtml/aid/2311) is very informative but I think that by itselft doesn't answer my question.
Thanks a lot,
IrYoKu
I was coding a script and have come to this problem:
I have a global variable called tasks, that contain objects of prototype task -I have tried to simplify the code-
tasks = new Array();
tasks[0] = new task;
tasks[0].taskR();
function task();
{
function taskR()
{
window.setTimeOut(tasks[0].taskR, 10);
}
}
What I want is an object that contains a function that call itselft recursively every 10 ms.
I pass to setTimeOut the function I want to call (not an expresion, the omission of the quotation marks is intentional), but the script don't work because it seems (this is my own theory) that the tasks[0].taskR called by setTimeOut is not the taskR that contain tasks[0]. It is treated as another function (maybe contained in the global scope of the script) and I don't understand very well this behaviour. If you try this script it will hang your navigator and probably your os (if Windows).
I know there are an easy work around to this, but I would like to know why this script is not working to get a better understanding of the javascript objects.
This page (http://www.faqts.com/knowledge_base/view.phtml/aid/2311) is very informative but I think that by itselft doesn't answer my question.
Thanks a lot,
IrYoKu