en.javascript.info/1-js/06-advanced-functions/09-call-apply-decorators/03-debounce/solution.md
2020-05-06 23:24:22 +03:00

333 B

function debounce(func, ms) {
  let timeout;
  return function() {
    clearTimeout(timeout);
    timeout = setTimeout(() => func.apply(this, arguments), ms);
  };
}

A call to debounce returns a wrapper. When called, it schedules the original function call after given ms and cancels the previous such timeout.