mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Merge pull request #433 from petejkim/master
added "collect" alias for "map"
This commit is contained in:
@@ -35,6 +35,9 @@ $(document).ready(function() {
|
|||||||
var doubled = _.map([1, 2, 3], function(num){ return num * 2; });
|
var doubled = _.map([1, 2, 3], function(num){ return num * 2; });
|
||||||
equals(doubled.join(', '), '2, 4, 6', 'doubled numbers');
|
equals(doubled.join(', '), '2, 4, 6', 'doubled numbers');
|
||||||
|
|
||||||
|
doubled = _.collect([1, 2, 3], function(num){ return num * 2; });
|
||||||
|
equals(doubled.join(', '), '2, 4, 6', 'aliased as "collect"');
|
||||||
|
|
||||||
var tripled = _.map([1, 2, 3], function(num){ return num * this.multiplier; }, {multiplier : 3});
|
var tripled = _.map([1, 2, 3], function(num){ return num * this.multiplier; }, {multiplier : 3});
|
||||||
equals(tripled.join(', '), '3, 6, 9', 'tripled numbers with context');
|
equals(tripled.join(', '), '3, 6, 9', 'tripled numbers with context');
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
|
|
||||||
// Return the results of applying the iterator to each element.
|
// Return the results of applying the iterator to each element.
|
||||||
// Delegates to **ECMAScript 5**'s native `map` if available.
|
// Delegates to **ECMAScript 5**'s native `map` if available.
|
||||||
_.map = function(obj, iterator, context) {
|
_.map = _.collect = function(obj, iterator, context) {
|
||||||
var results = [];
|
var results = [];
|
||||||
if (obj == null) return results;
|
if (obj == null) return results;
|
||||||
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
|
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
|
||||||
|
|||||||
Reference in New Issue
Block a user