Last active
April 19, 2018 20:59
-
-
Save jshcrowthe/a10263f6f88d274a309b156447f97488 to your computer and use it in GitHub Desktop.
Javascript Event Debounce (Run function X only once after Y ms)
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, delay) { | |
var timer = null; | |
return function () { | |
var context = this, args = arguments; | |
clearTimeout(timer); | |
timer = setTimeout(function () { | |
fn.apply(context, args); | |
}, delay); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Usage: