Lodash _.bindAll() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Util

Definition

Binds methods of an object to the object itself, overwriting the existing methods. Part of Lodash Util since 0.1.0 (stable — not deprecated).

Note: Does not set the length property of bound functions. It mutates the object and returns it.

Syntax

Call _.bindAll. Start with this line.

Lodash
_.bindAll(object, methodNames)
CallWhat it does
_.bindAll(object, methodNames)Primary signature.
_.bindAll(...)Call the util helper.

Prefer import bindAll from "lodash/bindAll" when you want a smaller bundle.

Library declarations
Lodash
_.bindAll(object, methodNames)

Parameters

ParameterDescription
objectRequired. Object whose methods are bound
methodNamesRequired. Names to bind (array and/or rest args)

Return Value

Return ValueDescription
*The same object (methods overwritten)

Lodash Examples

Example 1 — Official: Bind click

Bind one method so a detached callback still sees this.label.

Lodash
var view = {
  label: 'docs',
  click: function () {
    return 'clicked ' + this.label;
  }
};

_.bindAll(view, ['click']);

var handler = view.click;
console.log(handler());
// → "clicked docs"
Try It Yourself

How It Works

  1. Object. click reads this.label.
  2. Bind. _.bindAll(view, ['click']) replaces view.click.
  3. Detach. handler = view.click loses the object as receiver.
  4. Still works. Bound this stays view → "clicked docs".

Example 2 — Without bindAll

Same object, but the detached call loses this.

Lodash
var view = {
  label: 'docs',
  click: function () {
    return 'clicked ' + this.label;
  }
};

var handler = view.click;
console.log(handler());
// → "clicked undefined"  (strict: may throw)
Try It Yourself

How It Works

  1. Extract. handler is just a bare function.
  2. Call. handler() has no object receiver.
  3. this. In sloppy mode this.label is undefined.
  4. Fix. Use _.bindAll (or _.bind / arrows) before detaching.

Example 3 — Bind Multiple Methods

Pass an array of names when several handlers need binding.

Lodash
var view = {
  label: 'docs',
  click: function () { return 'click:' + this.label; },
  render: function () { return 'render:' + this.label; }
};

_.bindAll(view, ['click', 'render']);

console.log(view.click());
console.log(view.render());
// → "click:docs"
// → "render:docs"
Try It Yourself

How It Works

  1. List names. ['click', 'render'] selects both methods.
  2. Overwrite. Each is replaced with a bound version.
  3. Call. Both read this.label correctly.
  4. Use. Handy for a small set of event handlers on one object.

Example 4 — Variadic Method Names

Same result with separate string arguments.

Lodash
var view = {
  label: 'docs',
  click: function () { return 'clicked ' + this.label; }
};

_.bindAll(view, 'click');

var handler = view.click;
console.log(handler());
// → "clicked docs"
Try It Yourself

How It Works

  1. Rest args. 'click' is a method name.
  2. Same as array. Equivalent to ['click'].
  3. Result. Detached handler() still works.
  4. Pick a style. Use whichever reads clearer in your code.

Example 5 — bindAll vs _.bind

bindAll assigns back; _.bind returns a new function.

Lodash
var view = {
  label: 'docs',
  click: function () { return 'clicked ' + this.label; }
};

var withBind = _.bind(view.click, view);
console.log(withBind());           // "clicked docs"
console.log(view.click === withBind); // false

_.bindAll(view, 'click');
console.log(view.click());         // "clicked docs"
Try It Yourself

How It Works

  1. _.bind. Creates a new function; view.click is unchanged until you assign it.
  2. Compare. view.click === withBind is false.
  3. bindAll. Overwrites view.click in place.
  4. Choose. One-off callback → _.bind; several object methods → _.bindAll.

Browser & Runtime Support

_.bindAll is a Lodash Util helper since 0.1.0. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 0.1.0+

_.bindAll()

Available in [email protected] full builds and the lodash/bindAll modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 0.1+
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
_.bindAll Lodash 0.1.0+

Bottom line: Safe for production once Lodash is loaded. Prefer import bindAll from "lodash/bindAll" for smaller bundles. Use it when several object methods are passed as callbacks and must keep this.

Frequently Asked Questions

_.bindAll(object, …methodNames) overwrites the named methods on object with versions bound to that object, then returns object. Official use: bind view.click so a detached handler still reads this.label.
Yes. It replaces the listed method properties in place. The same object reference is returned.
As an array (_.bindAll(obj, ['click'])) or as separate strings (_.bindAll(obj, 'click', 'render')). Both forms work in Lodash 4.
_.bind(fn, thisArg) returns one new function and does not assign it. _.bindAll binds many methods and writes them back onto the object.
In JavaScript, this depends on how a function is called. Passing obj.method as a callback calls it without obj as the receiver unless it was bound first.
Use import bindAll from "lodash/bindAll" or require("lodash/bindAll"). Full build: import _ from "lodash" then _.bindAll.

Next: _.cond()

Build if/else-style logic from predicate and function pairs.

_.cond() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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