Underscore.js _.bind() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Function

Definition

Bind a function to an object, meaning that whenever the function is called, the value of this will be the object. Optionally, pass arguments to pre-fill them (partial application) (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 _.bind. Start with this line.

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

Parameters

ParameterDescription
functionRequired. Function to wrap
objectRequired. Value of this inside the call
*argumentsOptional. Pre-filled leading arguments

Return Value

Return ValueDescription
*New bound function

Underscore.js Examples

Example 1 — Official: Bind this + Arg

Lock context and pre-fill the greeting.

Underscore
var func = function (greeting) {
  return greeting + ': ' + this.name;
};
func = _.bind(func, { name: 'moe' }, 'hi');
func();
// → 'hi: moe'
Try It Yourself

How It Works

  1. Object { name: 'moe' } becomes this.
  2. 'hi' is pre-filled as greeting.
  3. func() needs no arguments at call time.
  4. Result: 'hi: moe' — official example.

Example 2 — Why Binding Matters

Detaching a method loses this without _.bind.

Underscore
var person = {
  name: "Ada",
  greet: function () {
    return "hi " + this.name;
  }
};

var unbound = person.greet;
// unbound() → this is not person (often broken)

var bound = _.bind(person.greet, person);
bound();
// → 'hi Ada'
Try It Yourself

How It Works

  1. Method extract person.greet drops the object link.
  2. Plain call does not set this to person.
  3. _.bind(…, person) restores the context.
  4. Common bug with timers, events, and callbacks.

Example 3 — Bound Callback

Pass a method to another function safely.

Underscore
var counter = {
  n: 0,
  tick: function () {
    this.n += 1;
    return this.n;
  }
};

function runTwice(fn) {
  fn();
  return fn();
}

runTwice(_.bind(counter.tick, counter));
// → 2
// counter.n → 2
Try It Yourself

How It Works

  1. runTwice calls the function as a free callback.
  2. Bound tick still updates counter.n.
  3. Without bind, this.n would fail or hit the wrong object.
  4. Many methods? Prefer _.bindAll.

Example 4 — Pre-fill + Call-Time Args

Bound args come first; later args append.

Underscore
var join = function (a, b, c) {
  return [a, b, c].join("-");
};

var bound = _.bind(join, null, "A");
bound("B", "C");
// → 'A-B-C'

// Args only? Use _.partial instead:
_.partial(join, "A")("B", "C");
// → 'A-B-C'
Try It Yourself

How It Works

  1. "A" is pre-filled via _.bind.
  2. bound("B", "C") supplies the rest.
  3. null context when this is unused.
  4. Docs tip: use _.partial for partials without binding this.

Browser & Runtime Support

_.bind 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. Native Function.prototype.bind is also available in modern engines.

✓ Stable · Underscore 1.x

_.bind()

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
_.bind Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Prefer a pinned CDN version (e.g. [email protected]). Native fn.bind is fine in modern apps.

Frequently Asked Questions

_.bind(function, object, *arguments) returns a new function that always runs with this set to object. Extra arguments are pre-filled (partial application). Official: _.bind(func, {name: 'moe'}, 'hi')() → 'hi: moe'.
Passing a method as a callback often loses its object, so this becomes undefined or the global object. _.bind locks this to the object you choose.
_.bind sets this (and can pre-fill args). _.partial only pre-fills arguments and leaves this alone.
_.bind returns one new bound function. _.bindAll binds named methods in place on an object for use as event handlers.
No. It returns a new function; the original is unchanged.
Modern engines have fn.bind(thisArg, ...args) with similar behavior. _.bind is consistent inside Underscore codebases and older environments.

Next: _.bindAll()

Bind multiple named methods on an object so event handlers keep the right this.

_.bindAll() 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