frontend-challenges icon indicating copy to clipboard operation
frontend-challenges copied to clipboard

20 - throttle - javascript

Open jsartisan opened this issue 2 months ago • 0 comments

index.js

export function throttle(cb, delay = 250) {
  let shouldInvoke = true;

  return (...args) => {
    if (shouldInvoke) {
      shouldInvoke = false;
      cb.call(this, ...args);

      setTimeout(() => {
        shouldInvoke = true;
      }, delay);
    }
  };
}

jsartisan avatar Sep 20 '25 05:09 jsartisan