Skip to content

Commit

Permalink
jquery core: Simplifying isEmptyObject() and adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
flesler committed Jul 16, 2009
1 parent 991d039 commit a38a5cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core.js
Expand Up @@ -292,9 +292,9 @@ jQuery.extend({
},

isEmptyObject: function( obj ) {
var name = "";
for(name in obj) break;
return !name;
for(var name in obj)
return false;
return true;
},

// check if an element is in a (or is an) XML document
Expand Down
10 changes: 10 additions & 0 deletions test/unit/core.js
Expand Up @@ -599,3 +599,13 @@ test("jQuery.makeArray", function(){

ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );
});

test("jQuery.isEmptyObject", function(){
expect(2);

equals(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
equals(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );

// What about this ?
// equals(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
});

0 comments on commit a38a5cd

Please sign in to comment.