Re: [問題] 停止未命名的時間

看板Ajax作者 (米沙)時間15年前 (2010/05/22 10:55), 編輯推噓0(005)
留言5則, 3人參與, 最新討論串2/2 (看更多)
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
你要執行stop()去停止 new的時候存到變數吧
05/22 11:04, 2F

05/22 11:47, , 3F
他是寫 userjs ....所以沒有變數可以用...
05/22 11:47, 3F

05/22 12:16, , 4F
沒錯 XD ....樓上正解
05/22 12:16, 4F

05/23 23:44, , 5F
因為不只一個,更新數值,更新聊天室,跳出一個任意連結...
05/23 23:44, 5F
文章代碼(AID): #1BzqUcTP (Ajax)
文章代碼(AID): #1BzqUcTP (Ajax)