Created
March 12, 2019 18:09
-
-
Save cyan33/32cd3853efc25bdaf0c93d2640c35dbc to your computer and use it in GitHub Desktop.
debounce.js
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(fn, delay = 1000) { | |
let timeoutId = null; | |
return () => { | |
if (timeoutId) { | |
timeoutId = null; | |
} | |
timeoutId = setTimeout(fn, delay); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment