turtle-rock icon indicating copy to clipboard operation
turtle-rock copied to clipboard

debounce函数缺陷

Open PRC-Cc opened this issue 4 years ago • 0 comments

https://github.com/scofieldfan/turtle-rock/blob/e4598498e434836d0dcf0a40f1408d4ca02b73fc/src/util.js#L5

debounce(fun, delay, immediate) {
    let timer = null;
    return (...args) => {
        if (timer) { // 去掉判断语句即可
            clearTimeout(timer);
        } else {
            timer = setTimeout(() => {
                fun.apply(this, args);
            }, delay);
        }
    };
}

PRC-Cc avatar Apr 22 '20 15:04 PRC-Cc