4.17.11
3.10.1
2.4.2
1.3.1

_.bindAll(object, methodNames)

Binds methods of an object to the object itself, overwriting the existing method.

Note: This method doesn't set the "length" property of bound functions.

Since

0.1.0

Arguments

argument
object
methodNames
type
Object
...(string|string[])
description
The object to bind and assign the bound methods to.
The object method names to bind.

Returns

(array)

Example

var view = {
  label: "docs",
  click: function () {
    console.log(
      "clicked " + this.label
    );
  },
};

_.bindAll(view, ["click"]);
jQuery(element).on("click", view.click);
// => Logs 'clicked docs' when clicked.
var view = {
  label: "docs",
  click: function () {
    console.log("clicked " + this.label);
  },
};

_.bindAll(view, ["click"]);
jQuery(element).on("click", view.click);
// => Logs 'clicked docs' when clicked.