function throttle(fuct,delay){
let pre //先前的时间
let timeoutId //清除一次定时器
return function () {
let now = Data.now()
if(!pre || now>=pre+delay){
pre = now
fuct() //执行回调函数
}else{
clearTimeout(timeoutId)
timeoutId = setTimeout(()=>{
pre = null
},delay)
}
}
}
简单的防抖与节流