> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# after es-toolkit

Creates a new function that invokes the original function starting from the `n`-th call.

```typescript
const afterFunc = after(n, func);
```

## Usage

### `after(n, func)`

Use `after` when you want to ignore the first few calls and execute the function starting from the `n`-th call. This is useful when you need to perform an action only after a specific number of occurrences in events or asynchronous operations.

```typescript
import { after } from 'es-toolkit/function';

const afterFn = after(3, () => {
  console.log('executed');
});

// logs nothing
afterFn();
// logs nothing
afterFn();
// logs 'executed'
afterFn();
// logs 'executed'
afterFn();
```

#### Parameters


nnumberrequired

The number of calls required before `func` is executed.


funcFrequired

The function to be executed.

#### Returns

A new function that tracks the number of calls and executes `func` starting from the `n`-th call. Returns `undefined` for calls before the `n`-th call.

```typescript
(...args: Parameters<F>) => ReturnType<F> | undefined
```

#### Throws

Throws an error when `n` is not an integer or is negative.


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/reference/function/after.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
