Main ideas
We have to consider the main: JS native object, the host object (above the browser).
First, for the host object
The main judgment is that the DOM object and whether it is a Window object
Whether the DOM object Value.nodetype exists.
is the Window object, value! = NULL && value = = = Value.window;
For both of these are definitely not empty objects.
if (Value.nodetype | | IsWindow (value)) {return false;}
For JS native objects
Whether or not the return is false for itself to return false has ' false ', ' null ', ' "', ' ' undefined ', ' NaN ', ' 0 ' in this 6 case
These obviously cannot be empty objects.
Then determine whether an object is using Object.prototype.toString.call (value) = = = ' [Object Object] '; Abbreviation for IsObject
There is also a judgment to determine whether you have a Hasownprototype method.
if (!value | |!isobject (value) | |!value.hasownprototype) {return false;}
If none of these conditions are met,
You need to handle whether you have your own properties,
for (var key in value) {if (Value.hasownprototype (key)) {return false; }}
Full code:
function Isemptyobject (value) {if (Value.nodetype | | IsWindow (value)) {return false; } if (!value | |!isobject (value) | |!value.hasownprototype) {return false; } for (var key in value) {if (Value.hasownprototype (key)) {return false; }} return true;
JS to determine if it is an empty object