diff --git a/test/collections.js b/test/collections.js index 32a1ee1bf..912abaf26 100644 --- a/test/collections.js +++ b/test/collections.js @@ -197,6 +197,9 @@ $(document).ready(function() { test('collections: toArray', function() { ok(!_.isArray(arguments), 'arguments object is not an array'); ok(_.isArray(_.toArray(arguments)), 'arguments object converted into array'); + var a = [1,2,3]; + ok(_.toArray(a) !== a, 'array is cloned'); + equals(_.toArray(a).join(', '), '1, 2, 3', 'cloned array contains same elements'); var numbers = _.toArray({one : 1, two : 2, three : 3}); equals(numbers.join(', '), '1, 2, 3', 'object flattened into array'); diff --git a/underscore.js b/underscore.js index 61fdb6ed5..804a005e2 100644 --- a/underscore.js +++ b/underscore.js @@ -278,7 +278,7 @@ _.toArray = function(iterable) { if (!iterable) return []; if (iterable.toArray) return iterable.toArray(); - if (_.isArray(iterable)) return iterable; + if (_.isArray(iterable)) return slice.call(iterable); if (_.isArguments(iterable)) return slice.call(iterable); return _.values(iterable); };