Last active
October 25, 2018 14:06
-
-
Save malithmcr/055bcc354f8cca799d65d6e042a87249 to your computer and use it in GitHub Desktop.
javascript throttle
This file contains hidden or 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
/** | |
* throttle | |
* @param {fn} callback func | |
* @param {wait} number - wait time | |
* @public | |
*/ | |
function throttle(fn, wait) { | |
var time = Date.now(); | |
return function() { | |
if ((time + wait - Date.now()) < 0) { | |
fn(); | |
time = Date.now(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment