我无法使用 mootools 定期运行类函数。它运行良好,但随后我得到一个函数未定义错误。相关代码可以看这里: http: //gist.github.com/142298
问问题
998 次
1 回答
2
您没有正确调用定期函数,请参阅MooTools 文档。
在您的示例中,您运行该函数一次并尝试对其返回值使用周期性函数(因此直接记录您的第一条消息,而不是在 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);
}
});
您想要的是定期调用 iterateClock 具有指定周期、绑定和参数(作为数组)的函数:
this.clock = this.iterateClock.periodical(1000, this, [current, future]);
于 2009-07-08T19:09:47.500 回答