Throttle
节流函数总结
定义
ES6实现
function throttle(fn, wait) {
let timeout, lastTime = 0
return (...args) =>{
const currentTime = Date.now()
if(current >= lastTime + wait){
lastTime = current
fn(...args)
}else {
clearTimeout(timeout)
timeout = setTimout(()=> fn(...args), wait)
}
}
}最后更新于