Created
November 16, 2016 12:49
-
-
Save kogovsekmatic/337fa6465d8da1a24f4b900a413de768 to your computer and use it in GitHub Desktop.
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); | |
lock = true; | |
return res; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment