Function throttle

** Limits function execution to once per interval.**

Useful for rate-limiting frequent events like scrolling or key presses.

const logScroll = throttle(() => console.log("Scrolling..."), 500);
window.addEventListener("scroll", logScroll);
  • Type Parameters

    • T extends unknown[]

      Function arguments.

    Parameters

    • fn: ((...args: T) => void)

      The function to throttle.

        • (...args): void
        • Parameters

          • Rest...args: T

          Returns void

    • limit: number

      The time limit in milliseconds.

    Returns ((...args: T) => void)

    • A throttled function.
      • (...args): void
      • Parameters

        • Rest...args: T

        Returns void