Function: before()
ts
function before<TArgs, TResult>(n, fn): (...args) => TResult | undefined;Creates a function that invokes fn at most n - 1 times. 创建最多执行 n - 1 次的包装函数。
Type Parameters
| Type Parameter | Description |
|---|---|
TArgs extends unknown[] | Argument tuple / 参数元组 |
TResult | Return type / 返回类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
n | number | Maximum invocations before no-op / 最大调用次数(第 n 次起不再执行) |
fn | (...args) => TResult | Target function / 目标函数 |
Returns
Wrapped function / 包装函数
(...args) => TResult | undefined
Example
ts
const log = before(3, (x) => x)
log(1) // => 1
log(2) // => 2
log(3) // => undefinedSince
1.2.0