我尝试执行一些超时函数,这是类中的代码:
while($$('.visos_prekes ul li.simple').length > 0){
setTimeout(this.destroyByOne(), 5000);
}
destroyByOne: function(){
$$('.visos_prekes ul li.simple').each(function(e, key){
e.destroy();
if(key > 16){
return true;
}
});
},
但是这个函数执行时不会超时。我做错了什么?
最佳答案
这一行setTimeout(this.destroyByOne(), 5000);
应该是:
setTimeout(this.destroyByOne, 5000);
因为您需要向它传递函数处理程序(又名变量)......并且不是函数调用的结果(this.destroyByOne()
)。
关于javascript - 在 mootools 中使用超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15699266/