ホームページ  >  記事  >  ウェブフロントエンド  >  jQuery.isPlainObject()関数の使い方の詳しい説明

jQuery.isPlainObject()関数の使い方の詳しい説明

巴扎黑
巴扎黑オリジナル
2017-07-08 11:36:111518ブラウズ

jQuery.isPlainObject() 関数は、指定されたパラメーターが純粋なオブジェクトかどうかを判断するために使用されます。

いわゆる「純粋なオブジェクト」とは、オブジェクトが「{}」または「新しいオブジェクト」を通じて作成されることを意味します。

この関数はグローバル jQuery オブジェクトに属します。

構文

jQuery 1.4 静的関数を追加しました。
jQuery.isPlainObject( object )


Parameters

Parameters

Description

object 判定する必要がある任意の型の値。

注: ホスト オブジェクト (または ECMAScript 実行環境を完成させるためにブラウザー ホスト環境によって使用されるその他のオブジェクト) は、クロスプラットフォームの機能検出を実行することが困難です。したがって、$.isPlainObject() は、これらのオブジェクトのインスタンスに対してブラウザーごとに異なる結果を与える可能性があります。

戻り値

jQuery.isPlainObject()

関数

の戻り値は、指定されたパラメータが純粋なオブジェクトの場合は true を返し、それ以外の場合は false を返します。 例と説明

jQuery.isPlainObject() 関数の jQuery サンプル コードは次のとおりです:

//在当前页面内追加换行标签和指定的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

以上がjQuery.isPlainObject()関数の使い方の詳しい説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。