typeof null 也等于object 蜘澜!
所以可以使用((bar !== null) && (typeof bar ==="object"))
來判斷 //true
但是如果bar是一個函數(shù) 上面的解決方案就為false,如果你希望為true 可以用如下:
((bar !== null) && (typeof bar ==="object") && (typeof bar ==="function"))
但是如果bar是一個數(shù)組 上面的解決方案就為true, 例如var bar = [] 如果你希望為false 可以用如下:
((bar !== null) && (typeof bar ==="object") && (Object.prototype.toString(bar)! =="[object Array]"))
還有一個方法對空置、數(shù)組响疚、函數(shù)返回false 但對于對象為true:
((bar !== null) && (bar.constructor === Object))
或者使用JQuery:
((bar !== null) && (typeof bar ==="object") && (!&.isArray(bar))