diff --git a/test/arrays.js b/test/arrays.js index ff430648d..fc44fa366 100644 --- a/test/arrays.js +++ b/test/arrays.js @@ -12,6 +12,8 @@ $(document).ready(function() { equal(result, 4, 'works on an arguments object.'); result = _.map([[1,2,3],[1,2,3]], _.first); equal(result.join(','), '1,1', 'works well with _.map'); + result = (function() { return _.take([1,2,3], 2); })(); + equal(result.join(','), '1,2', 'aliased as take'); }); test("arrays: rest", function() { diff --git a/underscore.js b/underscore.js index 88da6e1d8..eb1f408e0 100644 --- a/underscore.js +++ b/underscore.js @@ -316,9 +316,9 @@ // --------------- // Get the first element of an array. Passing **n** will return the first N - // values in the array. Aliased as `head`. The **guard** check allows it to work - // with `_.map`. - _.first = _.head = function(array, n, guard) { + // values in the array. Aliased as `head` and `take`. The **guard** check + // allows it to work with `_.map`. + _.first = _.head = _.take = function(array, n, guard) { return (n != null) && !guard ? slice.call(array, 0, n) : array[0]; };