Function throttle

  • EN: Throttle, used to limit the frequency of function execution over time.

    ZH: 节流,用于限制函数在一段时间内的执行频率。

    Usage:

    const foo = throttle(() => {
    console.log('The function will be invoked at most once per every wait 1000 milliseconds.');
    }, 1000, { leading: true });

    Reference: Lodash

    Type Parameters

    • T extends ((...args) => any)

    Parameters

    • func: T
    • wait: number
    • options: {
          leading?: boolean;
          trailing?: boolean;
      } = {}
      • Optional leading?: boolean
      • Optional trailing?: boolean

    Returns ThrottleFunc<T>