【发布时间】:2013-10-01 23:38:29
【问题描述】:
我想执行一系列函数调用,每个函数调用都会在屏幕上发布一条 jGrowl 消息。当我立即执行此操作时,屏幕上不会显示任何内容。当我尝试在超时循环中设置延迟时,所有调用都会立即执行。
代码如下:
var tests = [];
tests.push("$.notification('this is a test');");
tests.push("$.notification('this is a test', 7);");
tests.push("$.notification({ message: 'this is a test', code: 'warning', sticky: false });");
tests.push("$.diagnostic({ message: 'click OK to continue', alert: true });");
tests.push("$.notification.erase();");
// 为什么这不起作用?
//>
功能等待(毫秒){
var 完成 = 假;
而(!完成){
设置超时(函数(){
完成=真;
}, 小姐)
}
}
这是控制台:
16.30.6.265: : Executing test[0]: $.notification('this is a test');
16.30.6.266: : Executing test[1]: $.notification('this is a test', 7);
16.30.6.266: : Executing test[2]: $.notification({ message: 'this is a test', code: 'warning', sticky: false });
16.30.6.266: : Executing test[3]: $.diagnostic({ message: 'click OK to continue', alert: true });
16.30.6.266: : Executing test[4]: $.notification.erase()
;
时间戳以毫秒为单位,因此不会发生延迟。
【问题讨论】:
-
(function(index){…});在做什么?您是否忘记将其作为 IEFE 调用?如果是这样,index应该用来做什么?
标签: javascript settimeout