这是我的计时器名称
renewRecompenses: function()
{
var timer = new Timer.Views.Layout();
var self = this;
var t = timer.getWorkingTimers(myPlayerId, function (resp){
self.resp = resp;
});
if (self.resp.length <= 0)
{
console.log("[TIMERS] On a pas de timers en cours");
}
else
{
var current;
for(var i=0;i<self.resp.length;i++)
{
current = self.resp[i];
console.log(current.attributes.timeEnd);
var g = new Timer.Views.Layout();
g.endlessTimer(current.attributes.timeEnd);
}
timer.bind('timerRenew', this.timerRenew, this);
}
},
和无尽的计时器功能
endlessTimer: function(endDate,t){
var myStdObject = function() {
var oThis = this;
this.callDelayed = function() {
currentDate = new Date();
var end = new Date(endDate);
var dif = end - currentDate;
console.log(dif);
if (dif <= 0){
clearTimeout(oThis.t);
console.log("FINISH");
}
else{
oThis.t = setTimeout(function() { oThis.callDelayed(); }, 1000);
}
};
};
var myInst = new myStdObject();
myInst.callDelayed();
}
我对setIntervals有点问题。事实上,我称之为EndlessTimer 2次。 console.log(dif);
没问题,计时器停在0以下。我的问题是第一个计时器结束时,“FINISH”被调用了2次!为什么?
提前多多感谢 皮尔