数组总是对象的实例 -Object
是 javascript 中的基础对象,并且由 new 创建的任何另一个对象都继承自。
new String('a') instanceof Object // true - also instance of String
new Number(3) instanceof Object // true -also instance of Number etc.
new Boolean(true) instanceof Object // true
new Date instanceof Object // true
new function(){} instanceof Object // true
[] instanceof Object // true - [] is equal to new Array
check this out:
Array = 1;
[] //TypeError: Cannot read property 'slice' of undefined
:)
然而
'a' instanceof Object // false
3 instanceof Object // false
试试这个:
var str = 'aaa',
arr = [],
myClass = function(){},
myClassInstance = new myClass;
str.constructor == String // true
arr.constructor == Array // true
myClassInstance.constructor == myClass // true