我无法使用 mootools 定期运行类函数。它运行良好,但随后我得到一个函数未定义的错误。相关代码可以看这里:http://gist.github.com/142298
最佳答案
您没有正确调用周期函数,请参阅 MooTools documentation .
在您的示例中,您运行该函数一次并尝试在其返回值上使用周期函数(因此您的第一条消息将直接记录,而不是在 1000 毫秒延迟之后):
var Main = new Class({
Implements: [Options],
options: {
releaseDate: '1 January, 2010'
},
initialize: function(options){
this.setOptions(options);
this.startClock();
},
startClock: function(){
var current = $time();
var future = new Date(this.options.releaseDate);
future = future.getTime();
this.clock = this.iterateClock(current, future).periodical(1000, this);
},
iterateClock: function(current, future){
var difference = future - current;
var days = Math.floor((difference / (60 * 60 * 24)) / 1000);
console.log(days);
}
});
您想要的是使用指定的周期、绑定(bind)和参数(作为数组)定期调用 iterateClock 函数:
this.clock = this.iterateClock.periodical(1000, this, [current, future]);
关于javascript - Mootools 期刊问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1094389/