Don't call iterable.toArray in _.toArray if not a function

This commit is contained in:
Michael Williamson
2012-03-10 16:00:23 +00:00
parent 34305bc85d
commit c8ec654e6b
2 changed files with 11 additions and 3 deletions

View File

@@ -301,7 +301,7 @@
// Safely convert anything iterable into a real, live array.
_.toArray = function(iterable) {
if (!iterable) return [];
if (iterable.toArray) return iterable.toArray();
if (iterable.toArray && _.isFunction(iterable.toArray)) return iterable.toArray();
if (_.isArray(iterable)) return slice.call(iterable);
if (_.isArguments(iterable)) return slice.call(iterable);
return _.values(iterable);