Code & Beyond: Eugene’s Dev Journey

Back

debounce.js
// Generic debounce function
const debounce = function (fn, delay = 16 /* 60fps */) {
  let timeout;

  return function (...args) {
    const context = this;
    if (timeout) clearTimeout(timeout);
    timeout = setTimeout(() => {
      fn.apply(context, args);
    }, delay);
  };
};
js
debounce.js
https://eugenejeon.me/blog/snippet-debounce.js/
Author Eugene
Published at 2025년 2월 27일