增加防抖方法DebounceImmediately
This commit is contained in:
parent
8d58cb43b3
commit
47bcbba772
20
JS/DebounceImmediately.js
Normal file
20
JS/DebounceImmediately.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user