From: Ariel Flesler Date: Thu, 16 Jul 2009 15:16:44 +0000 (+0000) Subject: jquery core: Simplifying isEmptyObject() and adding tests. X-Git-Url: http://git.asbjorn.it/?p=jquery.git;a=commitdiff_plain;h=a38a5cd531a328319f8b7f3f33a84044b54591ce jquery core: Simplifying isEmptyObject() and adding tests. --- diff --git a/src/core.js b/src/core.js index 74b9fee..a71656d 100644 --- a/src/core.js +++ b/src/core.js @@ -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 diff --git a/test/unit/core.js b/test/unit/core.js index a6f490c..8aa883a 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -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" ); +}); \ No newline at end of file