# 防抖、节流
// 节流
function throttle(fn, interval) {
let flag = true;
return function(...args) {
if (flag){
flag = false;
setTimeout(() => {
fn.apply(this, args);
flag = true;
}, interval);
}
}
}
// 防抖
function debounce(fn, interval) {
let timer = null;
return function (...args) {
if(timer) clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(this, args);
}, interval);
}
}