diff --git a/test/collections.js b/test/collections.js index af4306482..e76cae88a 100644 --- a/test/collections.js +++ b/test/collections.js @@ -789,6 +789,7 @@ equal(_.size(new String('hello')), 5, 'can compute the size of string object'); equal(_.size(null), 0, 'handles nulls'); + equal(_.size(0), 0, 'handles numbers'); }); test('partition', function() { diff --git a/underscore.js b/underscore.js index 04cdc067a..d45194475 100644 --- a/underscore.js +++ b/underscore.js @@ -127,7 +127,7 @@ // Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1; var isArrayLike = function(collection) { - var length = collection && collection.length; + var length = collection != null && collection.length; return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX; };