【发布时间】:2017-01-26 01:32:32
【问题描述】:
function test(){
setTimeout(function(){
var now=new Date();
while((new Date()).getTime() < now.getTime()+5000){ }
console.log('p')
}, 0);
}
test();
test(); //it takes 10 seconds,the second test function runs after the first finished.
有人可以向我解释一下它是如何工作的吗?
【问题讨论】:
-
JavaScript 不是“多线程的”;函数串行执行,而不是并行执行。
标签: javascript asynchronous settimeout