防抖: 一般用在搜索框搜索 , 一段时间内只执行最后一次即可,
他的应用也是一个定时器的应用
function debounce (fn, delay = 300, immiedate) {
let timer = null
return (...args) => {
clearTimeOut(timer)
if(immiedate && !timeout) {
fn.apply(this, args)
}
timer = setTimeOut(() => {
fn.apply(this, args)
}, delay)
}
}