| /** |
| * Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/> |
| * Build: `lodash modularize underscore exports="node" -o ./underscore/` |
| * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/> |
| * Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE> |
| * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors |
| * Available under MIT license <http://lodash.com/license> |
| */ |
| var baseFlatten = require('../internals/baseFlatten'), |
| createWrapper = require('../internals/createWrapper'), |
| functions = require('../objects/functions'); |
| |
| /** |
| * Binds methods of an object to the object itself, overwriting the existing |
| * method. Method names may be specified as individual arguments or as arrays |
| * of method names. If no method names are provided all the function properties |
| * of `object` will be bound. |
| * |
| * @static |
| * @memberOf _ |
| * @category Functions |
| * @param {Object} object The object to bind and assign the bound methods to. |
| * @param {...string} [methodName] The object method names to |
| * bind, specified as individual method names or arrays of method names. |
| * @returns {Object} Returns `object`. |
| * @example |
| * |
| * var view = { |
| * 'label': 'docs', |
| * 'onClick': function() { console.log('clicked ' + this.label); } |
| * }; |
| * |
| * _.bindAll(view); |
| * jQuery('#docs').on('click', view.onClick); |
| * // => logs 'clicked docs', when the button is clicked |
| */ |
| function bindAll(object) { |
| var funcs = arguments.length > 1 ? baseFlatten(arguments, true, false, 1) : functions(object), |
| index = -1, |
| length = funcs.length; |
| |
| while (++index < length) { |
| var key = funcs[index]; |
| object[key] = createWrapper(object[key], 1, null, null, object); |
| } |
| return object; |
| } |
| |
| module.exports = bindAll; |