Created
May 20, 2020 03:15
-
-
Save adamjgrant/b408200c205779f79eb96ecfb95518f8 to your computer and use it in GitHub Desktop.
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
let debounce, debounceQueue; | |
debounceQueue = {}; | |
debounce = function(fn, id, delay, args, that) { | |
delay = delay || 1000; | |
that = that || this; | |
args = args || new Array(); | |
if (typeof debounceQueue[id] !== "object") { | |
debounceQueue[id] = new Object(); | |
} | |
if (typeof debounceQueue[id].debounceTimer !== "undefined") { | |
clearTimeout(debounceQueue[id].debounceTimer); | |
} | |
return debounceQueue[id] = { | |
fn: fn, | |
id: id, | |
delay: delay, | |
args: args, | |
debounceTimer: setTimeout(function() { | |
debounceQueue[id].fn.apply(that, debounceQueue[id].args); | |
return debounceQueue[id] = void 0; | |
}, delay) | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment