From 978255b7780952f7603d24f78485b1d90a6e2dfa Mon Sep 17 00:00:00 2001 From: Peter Jihoon Kim Date: Fri, 13 Jan 2012 20:09:50 +0800 Subject: [PATCH] added "collect" alias for "map" --- test/collections.js | 3 +++ underscore.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test/collections.js b/test/collections.js index 46bcdf2af..cff9763ce 100644 --- a/test/collections.js +++ b/test/collections.js @@ -35,6 +35,9 @@ $(document).ready(function() { var doubled = _.map([1, 2, 3], function(num){ return num * 2; }); 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}); equals(tripled.join(', '), '3, 6, 9', 'tripled numbers with context'); diff --git a/underscore.js b/underscore.js index 096a4800d..9c8bcc2b0 100644 --- a/underscore.js +++ b/underscore.js @@ -89,7 +89,7 @@ // Return the results of applying the iterator to each element. // Delegates to **ECMAScript 5**'s native `map` if available. - _.map = function(obj, iterator, context) { + _.map = _.collect = function(obj, iterator, context) { var results = []; if (obj == null) return results; if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);