Created
September 14, 2019 15:58
-
-
Save sslotsky/e95bb205f3121e537f1d6a99c99593da 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
function debounce(fn, interval) { | |
let timeout; | |
return function(...args) { | |
clearTimeout(timeout); | |
return new Promise(resolve => { | |
timeout = setTimeout(() => resolve(fn(...args)), interval); | |
}); | |
} | |
} | |
const debounced = debounce(() => console.log("hello"), 200); | |
window.addEventListener('keydown', () => { | |
debounced().then(() => console.log("well hello to you too!")); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment