1.实例继承原型对象的属性和方法
[].constructor.name - "Array"
2. instanceof 方法判断对象原型链上是否存在某个构造函数
[] instanceof Array - true
3. toString 对对象的处理 (
推荐,不存在跨域问题
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
var xArray = window.frames[window.frames.length - 1].Array;
var arr = new xArray(1, 2, 3);
console.log(arr instanceof Array); // false
console.log(arr.constructor === Array); // false
console.log(Object.prototype.toString.call(arr)==='[object Array]'); // true
)
Object.prototype.toString.call([]) - "[object Array]"
扩展: in hasOwnProperty 之间区别
in操作符只要通过对象能访问到属性就返回true。 (遍历对象直系属性上无实际意义)
hasOwnProperty()只在属性存在于实例中时才返回true。