Created
May 27, 2018 23:11
-
-
Save mrchief/a7e8938ee96774f05644905b37f09536 to your computer and use it in GitHub Desktop.
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
const debounce = (func, wait, immediate) => { | |
let timeout | |
return (...args) => { | |
const later = () => { | |
timeout = null | |
if (!immediate) func(...args) | |
} | |
const callNow = immediate && !timeout | |
clearTimeout(timeout) | |
timeout = setTimeout(later, wait) | |
if (callNow) func(...args) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment