// 父类
function Father(name) {
this.name = name;
}
Father.prototype.sayName = function() {
console.log(this.name);
}
// 另一个父类
function Mother(name) {
this.name = name;
}
Mother.prototype.sayHello = function() {
console.log('Hello ' + this.name);
}
// 子类
function Son(name) {
Father.call(this, name);
Mother.call(this, name);
}
// 继承方法
Son.prototype = Object.create(Father.prototype);
Object.assign(Son.prototype, Mother.prototype);
Son.prototype.constructor = Son;
let son = new Son('Kevin');
son.sayName(); // Kevin
son.sayHello(); // Hello Kevin
console.log(Son.prototype.constructor) //指向了Son本身
console.log(son instanceof Son) //true
console.log(son instanceof Father)//true
console.log(son instanceof Mother)//false
console