Docs wording. Invokes func when called nor more times.
Not once. Call 3 and 4 still run func — unlike _.once.
Need once? Wrap with _.once, or ignore extra calls yourself.
Contrast._.before stops calling func after its limit.
Example 5 — after vs before
Same n, opposite timing windows.
Lodash
var aLog = [];
var bLog = [];
var a = _.after(3, function (x) { aLog.push(x); });
var b = _.before(3, function (x) { bLog.push(x); });
[1, 2, 3, 4].forEach(function (x) {
a(x);
b(x);
});
aLog; // → [3, 4] // starts at call 3
bLog; // → [1, 2] // stops before call 3
Args. Both forward this and arguments when they do call func.
Compatibility
Browser & Runtime Support
_.after is a Lodash 4.x Function helper (since 0.1.0). It needs no special browser APIs beyond loading Lodash.
✓ Stable · Lodash 0.1.0+
_.after()
Available in [email protected] full builds and the lodash/after modular import. Works in evergreen browsers and Node / Bun / Deno when Lodash is installed.
100%With Lodash 4.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.afterLodash 4.x+
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import after from "lodash/after" for smaller builds.
Frequently Asked Questions
_.after(n, func) returns a new function that invokes func once it has been called n or more times. Earlier calls return undefined.
after waits until the nth call, then runs func on that call and every later call. before runs func only while the call count is below n, then freezes on the last result.
Yes. From the nth call onward, every invocation of the wrapper calls func again (unlike _.once).
Lodash coerces n with toInteger. When n is 0 or less, func runs on the first call.
_.after throws a TypeError with the message "Expected a function".
Use import after from "lodash/after" or require("lodash/after") for tree-shaking. Full build: import _ from "lodash" then _.after.