2009-07-07 73 views

回答

2

你沒有正確地調用定期功能,請參閱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); 
    } 
}); 

你想要什麼是定期調用具有指定週期,綁定和參數(作爲數組)的iterateClock函數:

this.clock = this.iterateClock.periodical(1000, this, [current, future]); 
+0

他在mootools郵件列表上得到了相同的答案。解決這個問題的另一種方法是使用匿名函數作爲閉包,並將其應用於其原始代碼中。 – 2009-07-10 13:29:55