Created
January 25, 2019 13:13
-
-
Save genbliz/f09497a256ab2012689090246a1f3cf9 to your computer and use it in GitHub Desktop.
Simple JavaScript Debounce
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
var debounceTimeoutHolder = {}; | |
function debounceSimple(id, wait, cb) { | |
if (debounceTimeoutHolder[id]) { | |
clearTimeout(debounceTimeoutHolder[id]); | |
} | |
debounceTimeoutHolder[id] = setTimeout(function() { | |
cb(); | |
}, wait); | |
} | |
// Usage: | |
debounceSimple("d_01", 2000, function() { | |
// Next action here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment