I need to let a piece of code always run independently of other code. Is there a way of creating a thread in javascript to run this function?
–why setTimeout doesn’t worked for me
I tried it, but it runs just a single time. And if I call the function recursively it throws the error “too much recursion” after some time. I need it running every 100 milis (it’s a communication with a embedded system).
–as you ask, here goes some code
function update(v2) {
// I removed the use of v2 here for simplicity
dump("update\n"); // this will just print the string
setTimeout(new function() { update(v2); }, 100); // this try doesn't work
}
update(this.v);
It throws “too much recursion”.
Get rid of the
newkeyword for the function you’re passing tosetTimeout(), and it should work.Or just use
setInterval().EDIT: Referenced
this.vin a variable since I don’t know what the value ofthisis in your application.