如何在underscore.js中的_.each循环的每次迭代中添加延迟? [英] How can I add a delay inside each iteration of an _.each loop in underscore.js?
本文介绍了如何在underscore.js中的_.each循环的每次迭代中添加延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在_.each循环的每次迭代中添加延迟,以便将内部函数的调用空间缩短1秒?
How can I add a delay inside each iteration of an _.each loop to space out the calling of an interior function by 1 second?
_.each(this.rows, function (row, i) {
row.setChars(msg[i] ? msg[i] : ' ');
});
推荐答案
您不需要额外的IIFE
You don't need extra IIFE
_.each(this.rows, function (row, i) {
setTimeout(function () {
row.setChars(msg[i] ? msg[i] : ' ');
}, 1000 * i);
});
因为你没有在显式的中为$ c做这件事$ c>循环。
since you're not doing it in an explicit for
loop.
这篇关于如何在underscore.js中的_.each循环的每次迭代中添加延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文