Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jineeshjohn/5a10407e7d4e40ceff720403e9349993 to your computer and use it in GitHub Desktop.
Save jineeshjohn/5a10407e7d4e40ceff720403e9349993 to your computer and use it in GitHub Desktop.
debounce
<script>
let counter = 0;
const debounce = (fn, delay) => {
let timeoutId;
return () => {
clearTimeout(timeoutId);
timeoutId = setTimeout(fn, delay);
}
}
const foo = () => {
console.log('this horsam');
}
const betterFunction = debounce(foo, 3000);
</script>
<button onclick="betterFunction()">Show me</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment