react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / function / bindAll.js
80742 viewsvar baseFlatten = require('../internal/baseFlatten'),1createWrapper = require('../internal/createWrapper'),2functions = require('../object/functions'),3restParam = require('./restParam');45/** Used to compose bitmasks for wrapper metadata. */6var BIND_FLAG = 1;78/**9* Binds methods of an object to the object itself, overwriting the existing10* method. Method names may be specified as individual arguments or as arrays11* of method names. If no method names are provided all enumerable function12* properties, own and inherited, of `object` are bound.13*14* **Note:** This method does not set the "length" property of bound functions.15*16* @static17* @memberOf _18* @category Function19* @param {Object} object The object to bind and assign the bound methods to.20* @param {...(string|string[])} [methodNames] The object method names to bind,21* specified as individual method names or arrays of method names.22* @returns {Object} Returns `object`.23* @example24*25* var view = {26* 'label': 'docs',27* 'onClick': function() {28* console.log('clicked ' + this.label);29* }30* };31*32* _.bindAll(view);33* jQuery('#docs').on('click', view.onClick);34* // => logs 'clicked docs' when the element is clicked35*/36var bindAll = restParam(function(object, methodNames) {37methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);3839var index = -1,40length = methodNames.length;4142while (++index < length) {43var key = methodNames[index];44object[key] = createWrapper(object[key], BIND_FLAG, object);45}46return object;47});4849module.exports = bindAll;505152