Skip to content

Instantly share code, notes, and snippets.

View FlyingPig-99's full-sized avatar

Logan FlyingPig-99

View GitHub Profile
@FlyingPig-99
FlyingPig-99 / debounce.js
Created June 6, 2018 09:19 — forked from anaibol/debounce.js
ES6 debounce
export default function debounce(func, wait, immediate) {
let timeout
return function(...args) {
clearTimeout(timeout)
timeout = setTimeout(() => {
timeout = null
if (!immediate) func.apply(this, args)
}, wait)
if (immediate && !timeout) func.apply(this, [...args])
}