Created
July 26, 2020 17:30
-
-
Save jineeshjohn/5a10407e7d4e40ceff720403e9349993 to your computer and use it in GitHub Desktop.
debounce
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
<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