UNPKG

saven

Version:
22 lines (19 loc) 473 B
export function throttle (fn, threshhold, scope) { threshhold || (threshhold = 250) let last, deferTimer return function () { let context = scope || this let now = +new Date() let args = arguments if (last && now < last + threshhold) { clearTimeout(deferTimer) deferTimer = setTimeout(() => { last = now fn.apply(context, args) }, threshhold) } else { last = now fn.apply(context, args) } } }