Created
May 19, 2016 19:20
-
-
Save rlemon/21ffaccd3332bbfb18e6a30683771970 to your computer and use it in GitHub Desktop.
debounce js
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 debounce(fn, time) { | |
let deltaTime = Date.now(); | |
return function(event) { | |
if (Date.now() - deltaTime >= time) { | |
fn.call(this, event); | |
deltaTime = Date.now(); | |
} | |
}.bind(this) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment