var obj = {};
1、toString(推薦),只有當參數為{} 或者 new Object()時才會成立。
Object.prototype.toString.call(obj) === '[object Object]'
2、constructor,使用該函數也能判斷是否是對象,但是當參數為null時,會出現錯誤。
obj.constructor === Object
3、instanceof 需要注意的是由於數組也是對象,因此用 arr instanceof Object 也為true。
obj instanceof Object
4、typeof
typeof obj === Object // 根據typeof判斷對象也不太准確 表達式 參數值 返回值 typeof undefined 'undefined' typeof null 'object' typeof true 'boolean' typeof 123 'number' typeof "abc" 'string' typeof function() {} 'function' typeof {} 'object' typeof [] 'object'
5、$.isPlainObject()
判斷指定參數是否是一個純粹的對象(所謂"純粹的對象",就是該對象是通過"{}"或"new Object"創建的。)
$.isPlainObject(obj)