Files
30-seconds-of-code/test/debounce/debounce.js
2018-02-04 17:38:39 +02:00

10 lines
233 B
JavaScript

const debounce = (fn, wait = 0) => {
let inDebounce;
return function() {
const context = this,
args = arguments;
clearTimeout(inDebounce);
inDebounce = setTimeout(() => fn.apply(context, args), wait);
};
};
module.exports = debounce;