Open
Description
Description
On version 3.6.0, I found a vulnerability,I find that the method of detecting empty objects is not perfect.
isEmptyObject: function( obj ) {
var name;
for ( name in obj ) {
return false;
}
return true;
},
The downside of writing this is that the properties of the prototype chain and the Symbol type are not taken into account,I have a better way to implement it as follows.
isEmptyObject: function( obj ) {
var keys = Object.keys(obj);
// 看浏览器是否支持 Symbol
if (typeof Symbol !== "undefined") {
keys = keys.concat(Object.getOwnPropertySymbols(obj));
}
return keys.length === 0;
}
Link to test case
This direct modification of the source code test is good, I do not have a service to run this test. I'm looking forward to hearing from you.
Metadata
Metadata
Assignees
Labels
No labels