UNPKG

bbo

Version:

bbo is a utility library of zero dependencies for javascript.

30 lines (24 loc) 560 B
'use strict'; /* eslint-disable no-invalid-this */ function debounce(fn, wait, callFirst) { var timeout; return function () { if (!wait) { return fn.apply(this, arguments); } var context = this; var args = arguments; var callNow = callFirst && !timeout; clearTimeout(timeout); timeout = setTimeout(function () { timeout = null; if (!callNow) { return fn.apply(context, args); } }, wait); if (callNow) { return fn.apply(this, arguments); } }; } module.exports = debounce;