This is especially usef " /> 99精品国产一区二区,一区二区免费看,国产精品毛片久久久久久久

中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

Prototype PeriodicalExecuter對象 學習

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.


這個對象就是可以周期性的執行某個方法,但是在它內部維持了一個狀態,可以防止由于某些原因一次調用沒執行,然后下一次調用又來了,這樣會造成連續執行兩次方法。上面的第二斷英文就是這個意思。

幫助文檔上說這個對象只提供了一個方法stop,但是在我看的源碼里還提供了一個事件onTimerEvent,應該可以在某個時候觸發這個事件。但幫助文檔上沒有給出示例。

這個對象源碼比較簡單,這里直接貼出來了,就不再注釋了:
復制代碼 代碼如下:
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();
} 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...

JavaScript技術Prototype PeriodicalExecuter對象 學習,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 中文字幕精品一区二区三区精品 | 国产人免费人成免费视频 | 亚洲午夜精品久久久久久app | www日韩高清 | 人人干人人爽 | 亚洲国产精品视频一区 | 亚洲高清免费观看 | 国产精品二区三区 | 日韩在线视频一区 | 一区二区在线免费观看 | 三级视频在线观看 | 日本成人中文字幕 | 欧美片网站免费 | 国产精品久久久久婷婷二区次 | 黄色av免费 | 欧美精品a∨在线观看不卡 欧美日韩中文字幕在线播放 | 亚洲第一av网站 | 亚洲精品 在线播放 | 九一视频在线观看 | 亚洲精品一 | 丁香综合| 国产日韩欧美在线观看 | 午夜一区二区三区在线观看 | 在线看一区二区三区 | 国产福利在线 | 精品国产免费人成在线观看 | 日本久久久久久 | 99久久久99久久国产片鸭王 | 日韩中文在线观看 | 尤物在线视频 | 亚洲欧美一区二区三区国产精品 | 热久久性 | 一区二区三区在线观看免费视频 | www.久久 | a中文在线视频 | 天天干夜夜操 | 欧美99| 亚洲国产网址 | 三级视频久久 | 久久不卡 | 一区二区三区在线看 |