防抖
//防抖
function debounce(fn,delay){
let timer = null
return function(){
if (timer) clearTimeout(timer)
timer = setTimeout( ()=>{
fn.call(this, ...arguments)
},delay)
}
}
节流
function throttle(fn,delay){
let flag = true
return function (){
if(flag){
setTimeout(()=>{
fn.call(this,...arguments)
flag = true
},delay)
}
flag = false
}
}