Created
March 13, 2022 21:40
-
-
Save Robert-96/748291775b8bc132dc7e66458db1edb8 to your computer and use it in GitHub Desktop.
Pure JS debouncing example
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 delay(callback, ms) { | |
var timer = 0; | |
return function() { | |
clearTimeout(timer); | |
timer = setTimeout(callback, ms); | |
}; | |
}; | |
document.getElementById('input').addEventListener(delay(function (event) { | |
console.log('Time elapsed!', event); | |
}, 500)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment