improve #isEmpty implementation. add 2 tests

This commit is contained in:
Mike Frawley
2010-02-17 09:48:29 -06:00
parent 386ee8ade9
commit 130e860ecf
2 changed files with 5 additions and 1 deletions

View File

@@ -60,6 +60,8 @@ $(document).ready(function() {
ok(_.isEmpty([]), '[] is empty');
ok(!_.isEmpty({one : 1}), '{one : 1} is not empty');
ok(_.isEmpty({}), '{} is empty');
ok(_.isEmpty(null), 'null is empty');
ok(_.isEmpty(), 'undefined is empty');
var obj = {one : 1};
delete obj.one;

View File

@@ -503,7 +503,9 @@
// Is a given array or object empty?
_.isEmpty = function(obj) {
return _.keys(obj).length == 0;
if (_.isArray(obj)) return obj.length===0;
for (var k in obj) return false;
return true;
};
// Is a given value a DOM element?