let type = []
type.constructor = "hello"
typeof
【不能进一步区分null、数组、对象...】
console.log(typeof type) // object
instanceof
【基本类型需用new声明,且还受继承影响】
console.log(type instanceof Array, type instanceof Object) // true true
constructor
【指向可以改变】
console.log(type.constructor) // hello
通用:Object.prototype.toString.call( )
console.log(Object.prototype.toString.call(type)) // [object Array]
console.log(Object.prototype.toString.call(type).replace(/\[object\s|\]/g, '')) // Array
判断数组
1. [] instanceof Array // true
2. [].constructor === Array // true
3. Object.prototype.toString.call([]) === '[object Array]' // true
4. Array.isArray([]) // true