Underscore.js _.after() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Function

Definition

Creates a wrapper of function that does nothing at first. From the count-th call onwards, it starts actually calling function (official Underscore docs). Useful for grouping asynchronous responses. Stable Function helper — not deprecated.

Pass the required arguments shown below. Underscore function helpers usually return a new function — check timing and call-count behavior carefully.

Syntax

Call _.after. Start with this line.

Underscore
_.after(count, function)
CallWhat it does
_.after(count, function)Primary signature.
_.after(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.after(count, function)

Parameters

ParameterDescription
countRequired. Call number when fn starts running
functionRequired. Original function to wrap

Return Value

Return ValueDescription
*New wrapper function

Underscore.js Examples

Example 1 — Ignore Early Calls

Show when the wrapped function starts running.

Underscore
var log = [];
var ready = _.after(3, function (msg) {
  log.push(msg);
});

ready("a");  // ignored
ready("b");  // ignored
ready("c");  // runs → log = ["c"]
ready("d");  // runs → log = ["c", "d"]
Try It Yourself

How It Works

  1. count = 3 — first two calls do nothing.
  2. Third call runs fn("c").
  3. Fourth call also runs — threshold is a start, not a stop.
  4. Arguments from each running call are forwarded to fn.

Example 2 — Official: Wait for All Saves

Simulate the docs’ “all notes saved” pattern with sync stubs.

Underscore
var notes = ["A", "B", "C"];
var log = [];

var render = function () {
  log.push("render");
};

var renderNotes = _.after(notes.length, render);

_.each(notes, function (note) {
  // pretend asyncSave succeeded:
  renderNotes();
});

// log → ["render"]  // after the 3rd success
Try It Yourself

How It Works

  1. count = notes.length (3).
  2. Each save success calls the same wrapper.
  3. Third success finally runs render.
  4. Docs say “run once” because there are exactly three callbacks — not because later calls are blocked.

Example 3 — _.after vs _.before

Opposite timing: start late vs stop early.

Underscore
var afterLog = [];
var beforeLog = [];

var a = _.after(3, function (n) { afterLog.push(n); });
var b = _.before(3, function (n) { beforeLog.push(n); return n; });

a(1); a(2); a(3); a(4);
// afterLog → [3, 4]

b(1); b(2); b(3); b(4);
// beforeLog → [1, 2]   // 3rd+ reuse last result
Try It Yourself

How It Works

  1. after(3) ignores 1–2, runs on 3+.
  2. before(3) runs on 1–2, then stops invoking (memoized result).
  3. Mirror tools for “start after N” vs “allow N−1 runs”.
  4. Need one run total? Prefer _.once.

Example 4 — _.after(1, fn)

A count of 1 means the first call already runs.

Underscore
var log = [];
var go = _.after(1, function (msg) {
  log.push(msg);
});

go("now");   // runs immediately
go("again"); // also runs
// log → ["now", "again"]
Try It Yourself

How It Works

  1. count-th call is call 1 — nothing is skipped.
  2. Later calls still run — not the same as _.once.
  3. _.once blocks repeats; _.after(1) does not.
  4. Choose deliberately based on whether repeats should fire.

Browser & Runtime Support

_.after ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.after()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.after Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.after(count, function) returns a wrapper that does nothing at first. From the count-th call onward, it starts calling the original function. Useful for grouping async responses.
No. From the count-th call onward, every call runs the function. In the official notes example it looks like once because each note saves exactly once (exactly count calls).
_.after starts running at call count and keeps going. _.before runs for the first count-1 calls, then freezes on the last return value.
_.once(fn) allows a single run. _.after delays the first run until a threshold, then allows every later call.
The first call already runs fn — count is 1, so the count-th call is the first one.
Fire n async tasks and pass the same wrapper as each success callback. When the n-th response arrives, your finish function runs.

Next: _.before()

Create a wrapper that runs at most count - 1 times, then returns the last result.

_.before() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful