Debounce

Create a debounced function that delays execution until after a specified wait period has elapsed since the last call.

Code

Boilerplates
const debounce = (fn, ms) => {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn(...args), ms);
  };
};

const log = debounce(() => console.log('called'), 100);
log();
return 'debounced';
Browser·fetch() may be limited by CORS

More JavaScript Snippets