Created
April 27, 2018 05:43
-
-
Save cyan33/c7b8587152ff69e3a1f3dd683047336a to your computer and use it in GitHub Desktop.
A debounce that makes more sense to me (written by myself)
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 debouce(fn, wait = 99) { | |
let timeout = null; | |
function process(args) { | |
fn(args); | |
timeout = null; | |
} | |
return function() { | |
if (!timeout) { | |
timeout = setTimeout(process.bind(null, arguments), wait); | |
} else { | |
clearTimeout(timeout) | |
timeout = setTimeout(process.bind(null, arguments), wait) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment