Code Snippets

function debounce(fn, wait = 250) {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn.apply(this, args), wait);
  };
}

const onResize = debounce(() => console.log('resized'), 200);
window.addEventListener('resize', onResize);