作者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