...

View Full Version : setTimeout



otnj2ee
08-06-2008, 12:38 AM
In a javascript, assume there are three sequencial lines:

var a = "1st line";

setTimeout("2ndLine()", 1000);

var b ="3rd line"

...

function 2ndLine(){
...

}

Obviously, the order of the execution is:

var a = "1st line";

then, setTimeout("2ndLine()", 1000);

Now once it hits this line, will it call the setTimeout function and wait for 1000ms, then execute the function 2ndLine(), then finally the var b ="3rd line"? OR

it call the setTimeout function, put the 2ndLine() on hold (for 1000ms), but at the mean time, go ahead execute the 3rd line, i.e., var b ="3rd line" (so in this case, it is possible for the execution of 2ndLine() to happen after the 3rd line)?




Thanks


Scott

ninnypants
08-06-2008, 01:24 AM
It will put secondline(); on hold but continue to run the rest of your script, so yes if you code it like this secondline() will execute after the third line or however many other lines that it can process in that second

A1ien51
08-06-2008, 03:28 PM
A simple test would tell you what happens



alert("1");
window.setTimeout("alert('2')",1000);
alert("3");


Eric

Kor
08-06-2008, 04:03 PM
setTimeout() is not a break, nor a return. It is a simple bomb clock. While the chronometer ticks, life goes on and the rest of the code lines keep running till the Boom!... :)

Trinithis
08-06-2008, 10:01 PM
Variable names cannot start with numbers.

ninnypants
08-06-2008, 11:01 PM
@Trinithis you're completely right. My mistake



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum