Last active
June 25, 2018 16:31
-
-
Save mersanuzun/7c659e5a975f144f93b75b9b26984619 to your computer and use it in GitHub Desktop.
Debounce example: It runs the passing function after keyup event is triggred and 500 milis is passed.
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(event, func) { | |
const target = event.target; | |
clearTimeout(target.setTimeoutId); | |
target.setTimeoutId = setTimeout(() => func(target.value), 500); | |
} | |
document.getElementById("name") | |
.addEventListener("keyup", (event) => { | |
debounce(event, (value) => { | |
console.log("Print it after 500ms delay. Value: ", value); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment