debounce
防抖:执行最后一次
examples
查看控制台输出
source code
const debounce = (fun, time = 300) => {
let timer;
return (...args) => {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fun(args);
}, time);
};
};
查看控制台输出
const debounce = (fun, time = 300) => {
let timer;
return (...args) => {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fun(args);
}, time);
};
};