javascript - Mootools 期刊问题

标签 javascript mootools

我无法使用 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/

相关文章:

javascript - 不间断ajax请求

JavaScript 根据另一个对象数组的属性过滤对象数组

javascript - 使用 jQuery 更改显示的项目数

javascript - 使用 jQuery 和 Mootools

javascript - 使用javascript加载部分内容

javascript - 将 google weather api 与 mootools 结合使用

javascript - 如何将 css 类添加到 react 中的组件?

javascript - 避免多次添加事件

css - Mootools 1.4.3背景淡入淡出效果

javascript - svg:使用 javascript 将 <text> 包裹在 <a> 中导致白页(无错误)