Function: after()
ts
function after<TArgs, TResult>(n, fn): (...args) => TResult | undefined;Creates a function that invokes fn only after being called n times. 创建仅在第 n 次及之后才会执行 fn 的包装函数。
Type Parameters
| Type Parameter | Description |
|---|---|
TArgs extends unknown[] | Argument tuple / 参数元组 |
TResult | Return type / 返回类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
n | number | Invocation threshold / 触发阈值 |
fn | (...args) => TResult | Target function / 目标函数 |
Returns
Wrapped function / 包装函数
(...args) => TResult | undefined
Example
ts
const run = after(3, () => 'ok')
run()
run()
run() // => 'ok'Since
1.2.0