d5bde424951662e81c8cb2267711072219c8122e
[yaffs-website] / node_modules / grunt-legacy-util / node_modules / lodash / bindAll.js
1 var arrayEach = require('./_arrayEach'),
2     baseFlatten = require('./_baseFlatten'),
3     bind = require('./bind'),
4     rest = require('./rest');
5
6 /**
7  * Binds methods of an object to the object itself, overwriting the existing
8  * method.
9  *
10  * **Note:** This method doesn't set the "length" property of bound functions.
11  *
12  * @static
13  * @memberOf _
14  * @category Util
15  * @param {Object} object The object to bind and assign the bound methods to.
16  * @param {...(string|string[])} methodNames The object method names to bind,
17  *  specified individually or in arrays.
18  * @returns {Object} Returns `object`.
19  * @example
20  *
21  * var view = {
22  *   'label': 'docs',
23  *   'onClick': function() {
24  *     console.log('clicked ' + this.label);
25  *   }
26  * };
27  *
28  * _.bindAll(view, 'onClick');
29  * jQuery(element).on('click', view.onClick);
30  * // => logs 'clicked docs' when clicked
31  */
32 var bindAll = rest(function(object, methodNames) {
33   arrayEach(baseFlatten(methodNames), function(key) {
34     object[key] = bind(object[key], object);
35   });
36   return object;
37 });
38
39 module.exports = bindAll;