数据类型:7
string, number, boolean, undefined, null, object, symbol
typeof:7
string, number, boolean, undefined, object, function, symbol
instanceof:
于检测构造函数的 prototype
属性是否出现在某个实例对象的原型链上。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| function C () {} function D () {}
var o = new C()
console.log(o instanceof C, o.__proto__ === C.prototype, '此时 o 的 __proto__:', o.__proto__, '此时 C 的 prototype:', C.prototype)
console.log(o instanceof D, o.__proto__ === D.prototype)
console.log(o instanceof Object, o.__proto__.__proto__ === Object.prototype)
C.prototype = {}
var o2 = new C()
console.log(o2 instanceof C)
console.log(o instanceof C, '此时 o 的 __proto__:', o.__proto__, '此时 C 的 prototype:', C.prototype) console.log('此时 D 的 prototype:', D.prototype);
D.prototype = new C() console.log('此时 D 的 prototype:', D.prototype); var o3 = new D()
console.log(o3 instanceof D, o3.__proto__ === D.prototype)
console.log(o3 instanceof C)
console.log(o3.__proto__ === D.prototype, D.prototype.__proto__ === C.prototype);
console.log(o3.__proto__.__proto__ === C.prototype);
|