Remove _.bindAll support for binding all methods when no method names are provided.

This commit is contained in:
John-David Dalton
2015-07-09 19:48:44 -07:00
parent ab26945eca
commit d58cda122d
2 changed files with 19 additions and 48 deletions

View File

@@ -6844,7 +6844,7 @@
* @memberOf _ * @memberOf _
* @category Function * @category Function
* @param {Object} object The object to bind and assign the bound methods to. * @param {Object} object The object to bind and assign the bound methods to.
* @param {...(string|string[])} [methodNames] The object method names to bind, * @param {...(string|string[])} methodNames The object method names to bind,
* specified as individual method names or arrays of method names. * specified as individual method names or arrays of method names.
* @returns {Object} Returns `object`. * @returns {Object} Returns `object`.
* @example * @example
@@ -6856,12 +6856,12 @@
* } * }
* }; * };
* *
* _.bindAll(view); * _.bindAll(view, 'onClick');
* jQuery('#docs').on('click', view.onClick); * jQuery('#docs').on('click', view.onClick);
* // => logs 'clicked docs' when the element is clicked * // => logs 'clicked docs' when the element is clicked
*/ */
var bindAll = restParam(function(object, methodNames) { var bindAll = restParam(function(object, methodNames) {
methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object); methodNames = baseFlatten(methodNames);
var index = -1, var index = -1,
length = methodNames.length; length = methodNames.length;

View File

@@ -1503,37 +1503,22 @@
(function() { (function() {
var args = arguments; var args = arguments;
test('should bind all methods of `object`', 1, function() { var source = {
function Foo() { '_a': 1,
this._a = 1; '_b': 2,
this._b = 2; '_c': 3,
this.a = function() { return this._a; }; '_d': 4,
} 'a': function() { return this._a; },
Foo.prototype.b = function() { return this._b; }; 'b': function() { return this._b; },
'c': function() { return this._c; },
var object = new Foo; 'd': function() { return this._d; }
_.bindAll(object); };
var actual = _.map(_.functions(object).sort(), function(methodName) {
return object[methodName].call({});
});
deepEqual(actual, [1, 2]);
});
test('should accept individual method names', 1, function() { test('should accept individual method names', 1, function() {
var object = { var object = _.clone(source);
'_a': 1,
'_b': 2,
'_c': 3,
'a': function() { return this._a; },
'b': function() { return this._b; },
'c': function() { return this._c; }
};
_.bindAll(object, 'a', 'b'); _.bindAll(object, 'a', 'b');
var actual = _.map(_.functions(object).sort(), function(methodName) { var actual = _.map(['a', 'b', 'c'], function(methodName) {
return object[methodName].call({}); return object[methodName].call({});
}); });
@@ -1541,20 +1526,10 @@
}); });
test('should accept arrays of method names', 1, function() { test('should accept arrays of method names', 1, function() {
var object = { var object = _.clone(source);
'_a': 1,
'_b': 2,
'_c': 3,
'_d': 4,
'a': function() { return this._a; },
'b': function() { return this._b; },
'c': function() { return this._c; },
'd': function() { return this._d; }
};
_.bindAll(object, ['a', 'b'], ['c']); _.bindAll(object, ['a', 'b'], ['c']);
var actual = _.map(_.functions(object).sort(), function(methodName) { var actual = _.map(['a', 'b', 'c', 'd'], function(methodName) {
return object[methodName].call({}); return object[methodName].call({});
}); });
@@ -1568,14 +1543,10 @@
}); });
test('should work with `arguments` objects as secondary arguments', 1, function() { test('should work with `arguments` objects as secondary arguments', 1, function() {
var object = { var object = _.clone(source);
'_a': 1,
'a': function() { return this._a; }
};
_.bindAll(object, args); _.bindAll(object, args);
var actual = _.map(_.functions(object).sort(), function(methodName) { var actual = _.map(args, function(methodName) {
return object[methodName].call({}); return object[methodName].call({});
}); });