Created
October 23, 2015 22:31
-
-
Save xfsnowind/cc857bda15605b275716 to your computer and use it in GitHub Desktop.
debounce method on blog "Introducing Javascript method debounce" on 2014/05/12
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 debounce(func, wait, immediate) { | |
| var timeout; | |
| return function () { | |
| var obj = this, argus = arguments; | |
| function delayed () { | |
| if (!immediate) { | |
| func.apply(obj, argus); | |
| } | |
| timeout = null; | |
| } | |
| if (timeout) { | |
| clearTimeout(timeout); | |
| } else if (immediate) { | |
| func.apply(obj, argus); | |
| } | |
| timeout = setTimeout(delayed, wait); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment