main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | import arrayEach from './_arrayEach.js';
|
---|
2 | import baseAssignValue from './_baseAssignValue.js';
|
---|
3 | import bind from './bind.js';
|
---|
4 | import flatRest from './_flatRest.js';
|
---|
5 | import toKey from './_toKey.js';
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Binds methods of an object to the object itself, overwriting the existing
|
---|
9 | * method.
|
---|
10 | *
|
---|
11 | * **Note:** This method doesn't set the "length" property of bound functions.
|
---|
12 | *
|
---|
13 | * @static
|
---|
14 | * @since 0.1.0
|
---|
15 | * @memberOf _
|
---|
16 | * @category Util
|
---|
17 | * @param {Object} object The object to bind and assign the bound methods to.
|
---|
18 | * @param {...(string|string[])} methodNames The object method names to bind.
|
---|
19 | * @returns {Object} Returns `object`.
|
---|
20 | * @example
|
---|
21 | *
|
---|
22 | * var view = {
|
---|
23 | * 'label': 'docs',
|
---|
24 | * 'click': function() {
|
---|
25 | * console.log('clicked ' + this.label);
|
---|
26 | * }
|
---|
27 | * };
|
---|
28 | *
|
---|
29 | * _.bindAll(view, ['click']);
|
---|
30 | * jQuery(element).on('click', view.click);
|
---|
31 | * // => Logs 'clicked docs' when clicked.
|
---|
32 | */
|
---|
33 | var bindAll = flatRest(function(object, methodNames) {
|
---|
34 | arrayEach(methodNames, function(key) {
|
---|
35 | key = toKey(key);
|
---|
36 | baseAssignValue(object, key, bind(object[key], object));
|
---|
37 | });
|
---|
38 | return object;
|
---|
39 | });
|
---|
40 |
|
---|
41 | export default bindAll;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.