节流函数
js
function debounce(fn, time = 500) {
let timer = null;
let context = this
return function (...args) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fn.apply(context, args);
}, time);
};
}