是否有sleep
比下面的pausecomp
函数(从此处获取)更好的方法来设计JavaScript ?
function pausecomp(millis)
{
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < millis);
}
这不是JavaScript中Sleep的重复-动作之间的延迟 ; 我希望在函数中间真正入睡,而不是在执行一段代码之前没有延迟。
I can understand the purpose of a sleep function if you have to deal with synchronous execution. The setInterval and setTimeout functions create a parallel execution thread which returns the execution sequence back to the main program, which is ineffective if you have to wait for a given result. Of course one may use events and handlers, but in some cases is not what is intended.