|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * Creates a function that invokes `func`, with the `this` binding and arguments
|
|---|
| 3 | * of the created function, while it's called less than `n` times. Subsequent
|
|---|
| 4 | * calls to the created function return the result of the last `func` invocation.
|
|---|
| 5 | *
|
|---|
| 6 | * @template F - The type of the function to be invoked.
|
|---|
| 7 | * @param {number} n - The number of times the returned function is allowed to call `func` before stopping.
|
|---|
| 8 | * - If `n` is 0, `func` will never be called.
|
|---|
| 9 | * - If `n` is a positive integer, `func` will be called up to `n-1` times.
|
|---|
| 10 | * @param {F} func - The function to be called with the limit applied.
|
|---|
| 11 | * @returns {(...args: Parameters<F>) => ReturnType<F> } - A new function that:
|
|---|
| 12 | * - Tracks the number of calls.
|
|---|
| 13 | * - Invokes `func` until the `n-1`-th call.
|
|---|
| 14 | * - Returns last result of `func`, if `n` is reached.
|
|---|
| 15 | * @throws {TypeError} - If `func` is not a function.
|
|---|
| 16 | * @example
|
|---|
| 17 | * let count = 0;
|
|---|
| 18 | * const before3 = before(3, () => ++count);
|
|---|
| 19 | *
|
|---|
| 20 | * before3(); // => 1
|
|---|
| 21 | * before3(); // => 2
|
|---|
| 22 | * before3(); // => 2
|
|---|
| 23 | */
|
|---|
| 24 | declare function before<F extends (...args: any[]) => any>(n: number, func: F): F;
|
|---|
| 25 |
|
|---|
| 26 | export { before };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.