Creates a version of a function that can only be called one time. Repeated calls have no further effect and return the value from the original call (official Underscore docs). 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 _.once. Start with this line.
Underscore
_.once(function)
Call
What it does
_.once(function)
Primary signature.
_.once(...)
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
_.once(function)
Parameters
Parameter
Description
function
Required. Function to wrap
Return Value
Return Value
Description
*
Wrapper that runs once
Underscore.js Examples
Example 1 — Run Only Once
Three wrapper calls — the original body runs a single time.
_.once 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
_.once()
Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.
100%With Underscore 1.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
_.onceUnderscore 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]). Native alternative: a closure with a called flag that stores the first return value.
Frequently Asked Questions
_.once(function) returns a version of the function that can only run one time. The first call executes the original and remembers its result; later calls return that same result without running again.
The value from the first call. Side effects in the original function happen only once.
_.once runs once total, ignoring later arguments. _.memoize can run many times — once per unique cache key.
_.once(fn) is the same idea as _.before(2, fn): allow the first call, then stop.
One-time initialization, setup, or handlers that must not fire twice (create a connection, bootstrap an app).