我在使用mootools定期运行一个类函数时遇到了问题。它运行得很好,但是我得到了一个函数未定义的错误。相关代码可以在这里看到:http://gist.github.com/142298
发布于 2009-07-08 19:09:48
您没有正确调用周期函数,请参阅MooTools documentation。
在您的示例中,您运行该函数一次,并尝试对其返回值使用周期性函数(因此,您的第一条消息将直接记录,而不是在1000ms延迟之后):
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]);https://stackoverflow.com/questions/1094389
复制相似问题