mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 14:37:49 +00:00
tweaking invoke implementation
This commit is contained in:
@@ -154,6 +154,13 @@ $(document).ready(function() {
|
||||
equals(result[1].join(', '), '1, 2, 3', 'second array sorted');
|
||||
});
|
||||
|
||||
test('collections: invoke w/ function reference', function() {
|
||||
var list = [[5, 1, 7], [3, 2, 1]];
|
||||
var result = _.invoke(list, Array.prototype.sort);
|
||||
equals(result[0].join(', '), '1, 5, 7', 'first array sorted');
|
||||
equals(result[1].join(', '), '1, 2, 3', 'second array sorted');
|
||||
});
|
||||
|
||||
test('collections: pluck', function() {
|
||||
var people = [{name : 'moe', age : 30}, {name : 'curly', age : 50}];
|
||||
equals(_.pluck(people, 'name').join(', '), 'moe, curly', 'pulls names out of objects');
|
||||
|
||||
@@ -208,7 +208,7 @@
|
||||
_.invoke = function(obj, method) {
|
||||
var args = slice.call(arguments, 2);
|
||||
return _.map(obj, function(value) {
|
||||
return (method ? value[method] : value).apply(value, args);
|
||||
return (method.call ? method || value : value[method]).apply(value, args);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user