直接贴代码for(var i=0;i<5;i++){ setTimeout('fn()',1000);}function fn(){console.log(i)}报错为TypeError: "callback" argument must be a function但是在chrome中用不会报错,可以运行。这是怎么回事?
1 回答
慕哥9229398
TA贡献1877条经验 获得超6个赞
nodejs环境下和浏览器环境下不同
在nodejs环境下
If callback is not a function, a TypeError will be thrown.
在浏览器环境下,也是不推荐使用的
An optional syntax allows you to include a string instead of a function, which is compiled and executed when the timer expires. This syntax is not recommended for the same reasons that make using eval() a security risk.
添加回答
举报
0/150
提交
取消