Intervals

suggest change

Standard

Keep the id if you will call clearInterval. These are two separate calls, not one script. The string form is eval'd in global scope. It is not the same as passing the function.

var int = setInterval(doSomething, 5000); // 5000 milliseconds
var int = setInterval("doSomething()", 5000); // avoid: this evaluates a string

Extra arguments after the delay are passed to doSomething.

Without overlapping

setInterval keeps scheduling while a slow doSomething is still running. The callbacks do not run in parallel, but they can pile up with no pause between them. To wait until the previous call finishes, and then wait 5 seconds, schedule the next turn yourself. arguments.callee throws in strict mode, so name the function:

function repeat() {
   doSomething();
   setTimeout(repeat, 5000);
}
repeat();

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents