检查实例化对象的原型链是否出现在构造函数的prototype上
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
class Child extends Person {
constructor(parentName, parentAge) {
super();
this.parentName = parentName;
this.parentAge = parentAge;
}
}
class Student extends Child {
constructor(classNumber) {
super();
this.classNumber = classNumber;
}
}
let xiaoMing = new Student('幼一');
//下面 Student实例化对象的原型链有等于Person的prototype
console.log(xiaoMing.__proto__.__proto__.__proto__===Person.prototype) // true
console.log(xiaoMing instanceof Person) // true
总结:
看对象的proto是否在另一对象prototype上,如果没有继续往proto链上找直到proto指向null才停止查找