first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

JavaScript: The Significance of setTimeout() and clearTimeout()

Many designs using a for or while loop structure may instead have needed the setTimeout() method of the window object calling a function recursively. The general form of this structure is:

function MyFunc() {
    //code here
    timeoutID = setTimeout("MyFunc()", 1000)
}

where timeoutID is a script-global variable. After MyFunc() is called, this structure then recursively calls MyFunc() every second until clearTimeout(timeoutID) is used. Unlike a for or while loop, this "loop" is time based.

mod date: 1999-02-10T02:16:55.000Z