This is especially usef " /> 91香蕉导航,波多野结衣在线观看网址,免费黄色看片网站

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

Prototype PeriodicalExecuter對象 學(xué)習(xí)

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.


這個(gè)對象就是可以周期性的執(zhí)行某個(gè)方法,但是在它內(nèi)部維持了一個(gè)狀態(tài),可以防止由于某些原因一次調(diào)用沒執(zhí)行,然后下一次調(diào)用又來了,這樣會(huì)造成連續(xù)執(zhí)行兩次方法。上面的第二斷英文就是這個(gè)意思。

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

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

看一下示例:
復(fù)制代碼 代碼如下:
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技術(shù)Prototype PeriodicalExecuter對象 學(xué)習(xí),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 玖玖在线精品 | 在线视频精品免费 | 欧美黄色片在线 | 国产资源福利 | 91精品国产品国语在线不卡 | 曰曰啪天天拍视频在线 | 69国产成人综合久久精 | 91社区视频在线观看 | 男女朋友做爽爽爽免费视频网 | 精品一区二区三区免费视频 | 国产美女精品一区二区三区 | 国产成人一区二区三区在线视频 | 一区一区三区产品乱码 | 国产成人禁片在线观看 | 久久这里有精品视频任我鲁 | 91福利国产在线观一区二区 | 国产日韩欧美一区二区三区视频 | 国产精品福利无圣光一区二区 | 99久久香蕉国产线看观香 | 真实子伦视频不卡 | 国产91久久最新观看地址 | 一区二区三区影视 | 伊人精品在线视频 | 91精品欧美综合在线观看 | 国产原创麻豆精品视频 | 日本vs欧美一区二区三区 | 韩国一级永久免费观看网址 | 99视频都是精品热在线播放 | 久久不卡一区二区三区 | 五月天综合色 | 久久综合九九亚洲一区 | 国产精品成人免费综合 | 欧美一区二区三区在线可观看 | 国产高清国内精品福利色噜噜 | 一区二区三区视频在线播放 | 视频综合网 | 亚洲国产婷婷综合在线精品 | 国产美女免费国产 | 美女一级毛片无遮挡内谢 | 自拍三区 | 久久久久国产视频 |