Home > Web Front-end > JS Tutorial > body text

Detailed explanation of jQuery.isPlainObject() function usage

巴扎黑
Release: 2017-07-08 11:36:11
Original
1550 people have browsed it

jQuery.isPlainObject() function is used to determine whether the specified parameter is a pure object.

The so-called "pure object" means that the object is created through "{}" or "new Object".

This function belongs to the global jQuery object.

Syntax

jQuery 1.4 Newly addedThe static function.

jQuery.isPlainObject( object )

Parameters

Parameters

Description

object Any type needs to be Arbitrary value to judge.

Note: Host objects (or other objects used by the browser host environment to complete the ECMAScript execution environment) are difficult to perform cross-platform feature detection. Therefore, $.isPlainObject() may give different results on different browsers for instances of these objects.

Return value

jQuery.isPlainObject()The return value of the function is of Boolean type. If the specified parameter is a pure object, it returns true, otherwise it returns false.

Example & Description

The jQuery sample code for the jQuery.isPlainObject() function is as follows:

//在当前页面内追加换行标签和指定的HTML内容
function w( html ){
    document.body.innerHTML += "<br/>" + html;
}
w( $.isPlainObject( { } ) ); // true
w( $.isPlainObject( new Object() ) ); // true
w( $.isPlainObject( { name: "CodePlayer"} ) ); // true
w( $.isPlainObject( { sayHi: function(){} } ) ); // true
w( $.isPlainObject( "CodePlayer" ) ); // false
w( $.isPlainObject( true ) ); // false
w( $.isPlainObject( 12 ) ); // false
w( $.isPlainObject( [ ] ) ); // false
w( $.isPlainObject( function(){ } ) ); // false
w( $.isPlainObject( document.location ) ); // false(在IE中返回true)
function Person(){
    this.name = "张三";
}
w( $.isPlainObject( new Person() ) ); // false
Copy after login

The above is the detailed content of Detailed explanation of jQuery.isPlainObject() function usage. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template