using setTimeout() and .call()
using setTimeout() and .call()
我有点坚持尝试将 setTimeout 设置为使用 .call() 方法进行的函数调用。
基本上,我有一个函数引用数组,然后逐个遍历它们,并以一定的 setTimeout 间隔调用它们。第一个函数触发了 aok,但第二个函数没有,我在 js 控制台中收到一个我不明白的错误 - 错误是 -
未捕获的类型错误:对象 73 没有方法"调用"
代码:
function scene1(){
alert("boo");
}
function scene2(){
alert("boo2");
}
var arrAnimation = [];
arrAnimation[0] = scene1;
arrAnimation[1] = scene2;
//step through the array
for (var i = 0; i < arrAnimation.length; i++){
setTimeout(arrAnimation[i],3000).call();
}
任何帮助将不胜感激。Dan
你不需要使用 call
- 你需要做的就是将函数传递给setTimeout
,它将自动运行:
setTimeout(arrAnimation[i],3000);
仅供参考,错误本身 - setTimeout
返回一个数字作为句柄,如果需要,可以稍后取消超时。 数字没有call
功能。
.call
方法放在错误的位置。 给你:
http://jsfiddle.net/JkLk2/
相关文章:
- Selenium WebDriver and JavaScript change
- call()和apply()实际上是用来欺骗方法处理类似数组的对象的
- PHP and Javascript functions
- Javascript Return and if/else
- SetTimeout and clearTimeout in Javascript
- lightbox in html 5 and javascript
- TimelineJS and AngularJS
- timeago.js with datatable and PHP
- javascript button ajax and php
- Ajax and Json with Rails
- Combine onload, onresize and onclick
- php布尔值's小写AND大写和数字布尔值'可以接受
- setTimeout and V8
- Jquery post and onclick
- using setTimeout() and .call()
- Ajax call and node.js
- Laravel and JQuery URL call
- 使用js-apply-and-call创建一个webtrend函数来消除重复
- what's the difference between 'call/apply' and &
- 何时以及为什么使用Call and Apply