diff --git a/test/collections.js b/test/collections.js index 2e684056f..2cb3f6b67 100644 --- a/test/collections.js +++ b/test/collections.js @@ -418,6 +418,9 @@ $(document).ready(function() { var numbers = _.toArray({one : 1, two : 2, three : 3}); equal(numbers.join(', '), '1, 2, 3', 'object flattened into array'); + + // _.toArray on a NodeList should not throw. + ok(_.isArray(_.toArray(document.childNodes))); }); test('size', function() { diff --git a/underscore.js b/underscore.js index d6e4e198f..dfe261029 100644 --- a/underscore.js +++ b/underscore.js @@ -358,7 +358,8 @@ // Safely convert anything iterable into a real, live array. _.toArray = function(obj) { if (!obj) return []; - if (obj.length === +obj.length) return slice.call(obj); + if (_.isArray(obj)) return slice.call(obj); + if (obj.length === +obj.length) return _.map(obj, _.identity); return _.values(obj); };