str*_*roz 6 javascript loops underscore.js
如何在_.each循环的每次迭代中添加延迟,以便将内部函数的调用空间缩短1秒?
_.each(this.rows, function (row, i) {
row.setChars(msg[i] ? msg[i] : ' ');
});
Run Code Online (Sandbox Code Playgroud)
zer*_*kms 11
您不需要额外的IIFE
_.each(this.rows, function (row, i) {
setTimeout(function () {
row.setChars(msg[i] ? msg[i] : ' ');
}, 1000 * i);
});
Run Code Online (Sandbox Code Playgroud)
因为你没有在显式for循环中这样做.