Last active
March 2, 2022 03:34
-
-
Save rijkvanzanten/da0131fb5513b8c3c819dc09c572bc99 to your computer and use it in GitHub Desktop.
Small debounce function, based on David Walsh's original
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
function debounce(callback, wait) { | |
var timeout; | |
return function() { | |
var context = this; | |
var args = arguments; | |
var later = function() { | |
timeout = null; | |
} | |
var callNow = !timeout; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
if (callNow) callback.apply(context, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment