Falcon.SugarApi/JS/DebounceImmediately.js

20 lines
449 B
JavaScript

/**
* DebounceImmediately跟Debounce的区别是会首先立即执行一次。
*/
class DebounceImmediately {
constructor(time) {
//执行间隔
this.timeout = time;
//计时器
this.timer = null;
}
run(func, ...args) {
if (this.timer) {
return;
}
this.timer = setTimeout(() => {
this.timer = null;
}, this.timeout);
func(...args);
}
}