🌐 AI搜索 & 代理 主页
Skip to content

Commit a38a5cd

Browse files
committed
jquery core: Simplifying isEmptyObject() and adding tests.
1 parent 991d039 commit a38a5cd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/core.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ jQuery.extend({
292292
},
293293

294294
isEmptyObject: function( obj ) {
295-
var name = "";
296-
for(name in obj) break;
297-
return !name;
295+
for(var name in obj)
296+
return false;
297+
return true;
298298
},
299299

300300
// check if an element is in a (or is an) XML document

test/unit/core.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,3 +599,13 @@ test("jQuery.makeArray", function(){
599599

600600
ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );
601601
});
602+
603+
test("jQuery.isEmptyObject", function(){
604+
expect(2);
605+
606+
equals(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
607+
equals(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );
608+
609+
// What about this ?
610+
// equals(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
611+
});

0 commit comments

Comments
 (0)