UNPKG

bbo

Version:

bbo is a utility library of zero dependencies for javascript.

28 lines (23 loc) 543 B
/* 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); } }; } export default debounce;