Skip to content

Instantly share code, notes, and snippets.

View YagamiLight126's full-sized avatar

Lelouch YagamiLight126

  • Shanghai
View GitHub Profile
@YagamiLight126
YagamiLight126 / 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])
}