Jquery.isemptyobject () function explanation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.