1)有人可以说明setTimeout如何在执行线程方面工作.
考虑:
function foo() { alert('foo'); }
function bar() { alert('bar'); }
setTimeout(foo,1000);
bar();
Run Code Online (Sandbox Code Playgroud)
要么
function foo() { alert('foo'); setTimeout(foo,1000); }
function bar() { alert('bar'); }
setTimeout(foo,1000);
bar();
Run Code Online (Sandbox Code Playgroud)
要么
function foo() { alert('foo'); setTimeout(foo,1000); }
function bar() { /* an execution that runs with unknown time */ }
setTimeout(foo,1000);
bar();
Run Code Online (Sandbox Code Playgroud)
要么
function foo() { alert('foo'); setTimeout(foo,1000); }
function bar() { /* some ajax call that reply with unknown time */ }
setTimeout(foo,1000);
bar();
Run Code Online (Sandbox Code Playgroud)
要么
function foo() { alert('foo'); setTimeout(foo,1000); } …Run Code Online (Sandbox Code Playgroud)