front-end-interview-handbook/utilities/debounce.js

9 lines
229 B
JavaScript

const debounce = (fn, time) => {
let timerId;
return function(...args) {
const functionCall = () => fn.apply(this, args);
clearTimeout(timerId);
timerId = setTimeout(functionCall, time);
};
};