简体   繁体   English

如何为Foreach循环添加setTimeout函数

[英]How to add setTimeout function for the Foreach loop

Hi want to set the timeout funtion for the Freach loop for the callback i am setting the timeout funtion. 您好想要为回调的Freach循环设置超时功能,我正在设置超时功能。 but its displaying Undifined error. 但显示未定义错误。 can anybody Explain me here is My code. 有人可以向我解释一下我的代码吗?

 function async(array,cb){ array.forEach(function () { setTimeout(cb,0); }) } async([1,2,3,4],function(i){ console.log(i); }); 

Try: 尝试:

 function async(array,cb){ array.forEach(function(e) { setTimeout(function() { cb(e); },0); }); } async([1,2,3,4,5], function(i) { console.log(i); }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM