This is a simple facility for periodical execution of a function. This essentially encapsulates the native clearInterval/setInterval mechanism found in native Window objects.
This is especially useful if you use one to interact with the user at given intervals (e.g. use a prompt or confirm call): this will avoid multiple message boxes all waiting to be actioned.
onTimerEvent: function() { if (!this.currentlyExecuting) { try { this.currentlyExecuting = true; this.execute(); } catch(e) { /* empty catch for clients that don"t support try/finally */ } finally { this.currentlyExecuting = false; } } } });
看一下示例: 复制代码 代码如下: new PeriodicalExecuter(function(pe) { if (!confirm("Want me to annoy you again later?")) pe.stop(); }, 5); // Note that there won"t be a stack of such messages if the user takes too long // answering to the question...