Re: [問題] 停止未命名的時間
var PeriodicalExecuter = Class.create({
initialize: function(callback, frequency) {
this.callback = callback;
this.frequency = frequency;
this.currentlyExecuting = false;
this.registerCallback();
},
registerCallback: function() {
this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency *
1000);
},
execute: function() {
this.callback(this);
},
stop: function() {
if (!this.timer) return;
clearInterval(this.timer);
this.timer = null;
},
onTimerEvent: function() {
if (!this.currentlyExecuting) {
try {
this.currentlyExecuting = true;
this.execute();
this.currentlyExecuting = false;
} catch(e) {
this.currentlyExecuting = false;
throw e;
}
}
}
});
這是 prototype 的 函式
看起來好像沒辦法停止.....還是直接把 PeriodicalExecuter 物件delect 掉
這樣還會跑嗎???
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.204.70.172
→
05/22 10:57, , 1F
05/22 10:57, 1F
→
05/22 11:04, , 2F
05/22 11:04, 2F
→
05/22 11:47, , 3F
05/22 11:47, 3F
→
05/22 12:16, , 4F
05/22 12:16, 4F
→
05/23 23:44, , 5F
05/23 23:44, 5F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
1
16
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章