看板 Ajax 關於我們 聯絡資訊
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
wxyy:那個遊戲執行的東西 可以稍微描述一下嘛 ? 05/22 10:57
emn178:你要執行stop()去停止 new的時候存到變數吧 05/22 11:04
wxyy:他是寫 userjs ....所以沒有變數可以用... 05/22 11:47
mesak:沒錯 XD ....樓上正解 05/22 12:16
mesak:因為不只一個,更新數值,更新聊天室,跳出一個任意連結... 05/23 23:44