函数防抖
export function debounce(fn, wait){
let timeout = null;
return function() {
if(timeout !== null) {
clearTimeout(timeout);
}
timeout = setTimeout(fn,wait)
}
}
节流
function throttler(fn,delay){
let flag = true;
return function(){
if(!flag){
return false // 休息
}
flag = false; // 营业
fn();
setTimeout(() => {
flag = true
}, delay)
}
}