Skip to content

Instantly share code, notes, and snippets.

@Robert-96
Created March 13, 2022 21:40
Show Gist options
  • Save Robert-96/748291775b8bc132dc7e66458db1edb8 to your computer and use it in GitHub Desktop.
Save Robert-96/748291775b8bc132dc7e66458db1edb8 to your computer and use it in GitHub Desktop.
Pure JS debouncing example
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