short circuit isEmpty for null/undefined

This commit is contained in:
Brad Dunbar
2012-01-30 10:15:04 -05:00
parent bdb3cb21f9
commit 5c6abc4453

View File

@@ -761,6 +761,7 @@
// Is a given array, string, or object empty?
// An "empty" object has no enumerable own-properties.
_.isEmpty = function(obj) {
if (obj == null) return true;
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
for (var key in obj) if (_.has(obj, key)) return false;
return true;