Skip to main content

防抖

export function debounce(fn, delay = 1000) {
let timer = null;
return function (...args) {
const context = this;
if (timer) {
clearTimeout(timer);
timer = null;
}
timer = setTimeout(() => {
fn.apply(context, args);
}, delay);
};
}