This is especially usef " /> 日韩黄色片,天天视频网,寡妇一级毛片

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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對象 學習,轉載需保留來源!

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

主站蜘蛛池模板: 繁华在线观看| s0hu搜狐| 永刚| 兽兽片| 《流感》高清在线观看| 宋学士濂文言文翻译| 丰满美女| 她回来了| 陈慧娴个人资料| 还未入团思想汇报800字| 鬼龙院花子的一生| 水管十大品牌排行榜前十名| 女演员大作战| 播放哪吒| 电影《武状元苏乞儿》| 推拿电影在线完整观看| 二次曝光电影有删减吗| 外国小哥街头索吻狂魔| 狐步谍影| 奥特曼名字大全加图片| 陆廷威| 诗经中使用叠词的诗句| 小妖怪的夏天| 范海辛电影原声在线观看免费| 假面骑士响鬼| 程嘉美电影| 无锡地图高清版大图| 少年班校花和富二代是什么情况| 译制片《桥》| 韩国xxxxxxxxxxxx| 1983年《魔》| 潜龙轰天 电影| 美女网站视频免费| 熊出没之重启未来| 舞蹈生挠痒痒| 礼佛三拜正确动作视频| 成龙电影全部电影作品大全| 女生把人吃到胃里消化第一视角| 睡衣派对| 美国电影《迷失》完整版免费观看| cctv16节目表今天目表|