Falcon.SugarApi/JS/DebounceImmediately.js

20 lines
449 B
JavaScript
Raw Normal View History

2023-08-21 15:18:31 +08:00
/**
* 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);
}
}