【发布时间】:2012-10-19 09:12:37
【问题描述】:
我正在使用 phidgets 库通过 nodejs 与物理设备进行交互。我已经将它们全部物理连接起来,我要做的就是确保我的开/关时间是准确的。
这将是问题所在,因为我什至无法通过控制台正确注销有关 setTimout 的内容。
基本上,我正在尝试执行以下操作:
for ( var i = 0; i < 4; i++ ) {
setTimeout( function(i){
console.log('Input: "' + i + '", Executed with timeout of ' + i*1000 + 'ms');
}(i), i*1000 );
};
但我的控制台只是吐出以下内容,没有超时。它是即时的。
Input: "0", Executed with timeout of 0ms
Input: "1", Executed with timeout of 1000ms
Input: "2", Executed with timeout of 2000ms
Input: "3", Executed with timeout of 3000ms
这与我想要的相差甚远。
关于发生了什么的任何想法?
【问题讨论】:
标签: javascript node.js timer dom-events settimeout