jQuery.isPlainObject()函數(shù)的返回值為Boolean類型,如果指定的參數(shù)是純粹的對象,則返回true,否則返回false。
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