Skip to content

Commit 66a5db5

Browse files
shakeelmohamedkamilogorek
authored andcommitted
utils: make isEmptyObject check prototype #940
1 parent 3858b07 commit 66a5db5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ function isString(what) {
3939
}
4040

4141
function isEmptyObject(what) {
42-
for (var _ in what) return false; // eslint-disable-line guard-for-in, no-unused-vars
42+
for (var _ in what) {
43+
if (what.hasOwnProperty(_)) {
44+
return false;
45+
}
46+
}
4347
return true;
4448
}
4549

test/utils.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ describe('utils', function() {
6464
it('should work as advertised', function() {
6565
assert.isTrue(isEmptyObject({}));
6666
assert.isFalse(isEmptyObject({foo: 1}));
67+
var MyObj = function() {};
68+
MyObj.prototype.foo = 0;
69+
assert.isTrue(isEmptyObject(new MyObj()));
70+
var myExample = new MyObj();
71+
myExample.bar = 1;
72+
assert.isFalse(isEmptyObject(myExample));
6773
});
6874
});
6975

0 commit comments

Comments
 (0)