diff options
Diffstat (limited to 'src/debounce.js')
-rw-r--r-- | src/debounce.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/debounce.js b/src/debounce.js new file mode 100644 index 0000000..02f1a1a --- /dev/null +++ b/src/debounce.js @@ -0,0 +1,8 @@ +export default function debounce (func, wait) { + let timeout + return function (...args) { + const context = this + clearTimeout(timeout) + timeout = setTimeout(() => func.apply(context, args), wait) + } +} |