Merge pull request #453 from braddunbar/isempty

Short Circuit `isEmpty` for null/undefined
This commit is contained in:
Jeremy Ashkenas
2012-01-30 07:21:03 -08:00

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;