jQuery.isEmptyObject()
function is used to determine whether a specified parameter is an empty object .
The so-called "empty object", that is, does not include any enumerable (custom) properties. In short, the object has no attributes that can be for...in
iterated through.
The function belongs to the global jQuery
object.
Grammar
JQuery 1.4 Adds this static function.
JQuery. Isemptyobject()
Parameters
Parameters |
Description |
Object |
Any value that needs to be judged by any type. |
Note : This parameter should always be a purely javascript Object
, because other types (such as DOM elements, original strings/numbers, host objects) may not get consistent results across browsers. To determine whether an object is a purely JavaScript object, you can use the $.isplainobject () method.
return value
jQuery.isEmptyObject()
The return value of the function is Boolean, or returns if the specified argument is an empty object true
false
.
Example & Description
jQuery.isEmptyObject()
is judged by the for...in
loop, and its source code section is as follows:
Isemptyobject: function ( obj ) {
var Name;< Span class= "PLN" >
for ( Name in obj {
return false; }
return true; } /span>
jQuery.isEmptyObject()
The jquery sample code for the function is as follows:
Appends a newline label and the specified HTML content to the current page
functionW(Html){
Document.Body.InnerHTML+= "<br/>" +Html;
}
W($.Isemptyobject( { } ) ); True
W($.Isemptyobject( New Object() ) ); True
W($.Isemptyobject( [ 0 ] ) ); False
W($.Isemptyobject( {Name: "Codeplayer"} ) ); False
W($.Isemptyobject( {Sayhi: function(){} } ) ); False
function User(){
}
User.Prototype.Word= "Hello";
Properties on custom prototype objects are also enumerable
W($.Isemptyobject( New User() ) ); False
/* Although it is not recommended to add custom properties to built-in objects such as empty arrays, Function, number, and so on, they are not allowed to be enumerated. Because the parameters of isemptyobject () should always be a purely object */
There are no elements in the array, and the properties cannot be iterated through the for...in
W($.Isemptyobject ( [ ] Span class= "pun") //true
//Function, number, string, etc. built-in objects also cannot be passed for ... In Iteration properties
W ( $. Isemptyobject ( function () { Alert ( "xxx" ) } ) Span class= "com" >//false
Jquery.isemptyobject () function in detail