作者mesak (米沙)
看板Ajax
標題Re: [問題] 停止未命名的時間
時間Sat May 22 10:55:30 2010
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
1F:→ wxyy:那個遊戲執行的東西 可以稍微描述一下嘛 ? 05/22 10:57
2F:→ emn178:你要執行stop()去停止 new的時候存到變數吧 05/22 11:04
3F:→ wxyy:他是寫 userjs ....所以沒有變數可以用... 05/22 11:47
4F:→ mesak:沒錯 XD ....樓上正解 05/22 12:16
5F:→ mesak:因為不只一個,更新數值,更新聊天室,跳出一個任意連結... 05/23 23:44