Underscore.js _.partial() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Function

Definition

Partially apply a function by filling in any number of its arguments, without changing its dynamic this — a close cousin of _.bind (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 _.partial. Start with this line.

Underscore
_.partial(fn, *arguments)
CallWhat it does
_.partial(fn, *arguments)Primary signature.
_.partial(...)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
_.partial(fn, *arguments)

Parameters

ParameterDescription
functionRequired. Function to partially apply
*argumentsOptional. Pre-filled values and/or _ gaps

Return Value

Return ValueDescription
*New specialised function

Underscore.js Examples

Example 1 — Pre-fill the First Argument

Official docs pattern — lock a to 5.

Underscore
var subtract = function (a, b) { return b - a; };
var sub5 = _.partial(subtract, 5);

sub5(20);
// → 15
Try It Yourself

How It Works

  1. Fix a. Partial stores 5 as the first argument.
  2. Call with 20. That becomes b.
  3. Compute. 20 - 5 yields 15.
  4. Specialised fn. sub5 always “subtracts 5 from” in this shape.

Example 2 — Leave a Gap with _

Fix a later argument; keep an earlier slot open.

Underscore
var subtract = function (a, b) { return b - a; };
var subFrom20 = _.partial(subtract, _, 20);

subFrom20(5);
// → 15
Try It Yourself

How It Works

  1. Placeholder. _ means “fill this from the call.”
  2. Fixed b. 20 is locked as the second argument.
  3. Call 5. Goes into the open first slot.
  4. Same math. Still subtract(5, 20) → 15.

Example 3 — Preset Logger

Fix the level once; pass only the message later.

Underscore
function log(level, message) {
  return "[" + level + "] " + message;
}

var info = _.partial(log, "INFO");
info("Server started");
// → "[INFO] Server started"
Try It Yourself

How It Works

  1. General API. log needs level + message.
  2. Specialise. info always uses "INFO".
  3. Shorter calls. Only the message is passed at use sites.
  4. Same idea. Build warn / error the same way.

Example 4 — Partial as a map Iteratee

Pre-fill a multiplier, then map over a list.

Underscore
function multiply(a, b) { return a * b; }

_.map([1, 2, 3], _.partial(multiply, 2));
// → [2, 4, 6]
Try It Yourself

How It Works

  1. Partial. First arg of multiply is fixed as 2.
  2. Map calls. Each value is passed as the next argument.
  3. Result. 2*1, 2*2, 2*3.
  4. No wrapper. You avoid writing n => multiply(2, n).

Browser & Runtime Support

_.partial 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

_.partial()

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

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
_.partial 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]). Native alternative: (...rest) => fn(fixed, ...rest) or Function.prototype.bind when you also need this.

Frequently Asked Questions

_.partial(function, *arguments) returns a new function with some arguments already filled in. Call-time arguments are supplied for the remaining positions.
Pass _ (the Underscore object) as a placeholder for an argument that should stay open until call time.
No. It only pre-fills arguments and leaves this dynamic. Use _.bind when you also need to fix this.
_.bind sets this (and can pre-fill args). _.partial only pre-fills args and never touches this.
No. It returns a new function; the original is unchanged.
No. It is a stable Underscore Function helper.

Next: _.memoize()

Cache expensive function results by their arguments.

_.memoize() →

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