Skip to content

@longmo-utils/common / throttle

Function: throttle()

ts
function throttle<T>(fn, delay): (...args) => void;

节流函数,限制函数执行频率

Type Parameters

Type Parameter
T extends (...args) => any

Parameters

ParameterTypeDescription
fnT要执行的函数
delaynumber节流时间间隔(毫秒)

Returns

节流后的函数

ts
(...args): void;

Parameters

ParameterType
...argsParameters<T>

Returns

void

Example

ts
const throttledFn = throttle(() => console.log('hello'), 300)
throttledFn() // 立即执行
throttledFn() // 300ms 内不执行

Released under the MIT License.