Returns the composition of a list of functions, where each function consumes the return value of the function that follows. In math terms, composing f, g, and h produces f(g(h())) (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 _.compose. Start with this line.
Underscore
_.compose(*functions)
Call
What it does
_.compose(*functions)
Primary signature.
_.compose(...)
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
_.compose(*functions)
Parameters
Parameter
Description
*functions
Required. Functions to compose (rightmost runs first)
Return Value
Return Value
Description
*
New composed function
Underscore.js Examples
Example 1 — Official: greet ∘ exclaim
Uppercase first, then greet.
Underscore
var greet = function (name) {
return "hi: " + name;
};
var exclaim = function (statement) {
return statement.toUpperCase() + "!";
};
var welcome = _.compose(greet, exclaim);
welcome("moe");
// → 'hi: MOE!'
Second: greet first → 'hi: moe', then uppercase whole string.
List order is the composition order.
For left-to-right reading, reverse the functions you pass.
Example 4 — Single Function
Composing one function is a thin wrapper.
Underscore
var double = function (n) { return n * 2; };
var only = _.compose(double);
only(5);
// → 10
// Still useful as a uniform “pipeline” API
// when sometimes you pass one step, sometimes many.
_.compose 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
_.compose()
Available in [email protected] (UMD / ESM). Right-to-left composition. 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
_.composeUnderscore 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
_.compose(*functions) returns a new function that is the composition of those functions. Official: _.compose(greet, exclaim)('moe') → 'hi: MOE!' which is greet(exclaim('moe')).
Right to left. The last function you pass gets the original arguments; each result flows leftward. Math style: f(g(h(x))).
Only the rightmost function. Every other function receives exactly one value — the previous return value.
_.compose is a fixed pipeline of outputs. _.wrap gives your wrapper the original function so it can call it conditionally and add before/after logic.
Underscore’s _.compose is right-to-left. For reading order left-to-right, reverse the function list (or use a custom pipe helper).
Yes. _.compose(fn) returns a function that simply calls fn with the given arguments.