//定时器单例模式
class UniqueTimer {
static timer = null;
static time = 0;
static getTimer(callback, time) {
if (this.timer === null || this.time !== time) {
clearInterval(this.timer);
this.timer = setInterval(() => {
callback();
}, time);
}
return this.timer;
}
static clearTimer() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
}
}
JS的定时器单例模式
最新推荐文章于 2022-11-09 16:42:52 发布