function throttle(fn,wait=3000){
let lastTime = Date.now(),
timeFlag = null
return function(...args){
let current = Date.now()
clearTimeout(timeFlag)
if(current - lastTime >= wait){
fn.apply(this,args)
lastTime = current
}else{
timeFlag = setTimeout(()=>{
fn.apply(this,args)
lastTime = current
},wait)
}
}
}
Last active
December 21, 2022 01:27
-
-
Save ghostcode/65b0f7455d48e2375650cc114e13e7c4 to your computer and use it in GitHub Desktop.
throttle
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment