1 var baseFlatten = require('../internal/baseFlatten'),
2 createWrapper = require('../internal/createWrapper'),
3 functions = require('../object/functions'),
4 restParam = require('./restParam');
6 /** Used to compose bitmasks for wrapper metadata. */
10 * Binds methods of an object to the object itself, overwriting the existing
11 * method. Method names may be specified as individual arguments or as arrays
12 * of method names. If no method names are provided all enumerable function
13 * properties, own and inherited, of `object` are bound.
15 * **Note:** This method does not set the "length" property of bound functions.
20 * @param {Object} object The object to bind and assign the bound methods to.
21 * @param {...(string|string[])} [methodNames] The object method names to bind,
22 * specified as individual method names or arrays of method names.
23 * @returns {Object} Returns `object`.
28 * 'onClick': function() {
29 * console.log('clicked ' + this.label);
34 * jQuery('#docs').on('click', view.onClick);
35 * // => logs 'clicked docs' when the element is clicked
37 var bindAll = restParam(function(object, methodNames) {
38 methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
41 length = methodNames.length;
43 while (++index < length) {
44 var key = methodNames[index];
45 object[key] = createWrapper(object[key], BIND_FLAG, object);
50 module.exports = bindAll;