0

クラス関数を mootools で定期的に実行するのに問題があります。正常に実行されますが、関数が未定義のエラーが発生します。関連するコードはここで見ることができます: http://gist.github.com/142298

4

1 に答える 1

2

定期的な関数を正しく呼び出していません。MooTools のドキュメントを参照してください。

あなたの例では、関数を1回実行し、その戻り値で定期的な関数を使用しようとします(したがって、最初のメッセージは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 に答える