Files
fc/dev/project/library/imports/cc/cce9668b-77ce-4538-8c54-028139fc2aef.js
2026-05-24 10:21:26 +08:00

44 lines
951 B
JavaScript

"use strict";
cc._RF.push(module, 'cce96aLd85FOIxUAoE5/Crv', 'Timer');
// Scripts/client/base/Timer.js
"use strict";
/*-----------------------------------------------------+
* 定时器相关处理
* @author whjing2012@163.com
+-----------------------------------------------------*/
var Timer = {
idx: 1,
timer: {},
getInstance: function getInstance() {
return this;
},
set: function set(func, time, num, id) {
time = time || 1000;
num = num || 1;
if (!id) {
id = this.idx++;
}
this.del(id);
this.timer[id] = window.setTimeout(function () {
if (num == 1) {
this.del(id);
} else {
this.set(func, time, num - 1, id);
}
func();
}.bind(this), time);
return id;
},
del: function del(id) {
if (this.timer.hasOwnProperty(id)) {
window.clearTimeout(this.timer[id]);
delete this.timer[id];
}
}
};
module.exports = Timer;
cc._RF.pop();