This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wait(fn, w){ | |
let last = new Date(0); | |
let res; | |
return function(...args){ | |
const time = new Date(); | |
if(last.getTime() + w < time.getTime()){ | |
res = fn.apply(this, args); | |
last = time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function throttle(fn, w){ | |
let lock; | |
let res; | |
return function(...args){ | |
if(lock){ | |
return res; | |
}else{ | |
setTimeout(() => lock = false, w); | |
res = fn.apply(this, args); |