SOURCE

//寄生组合式继承
function Parent(name) {
    this.name = name;
}
Parent.prototype.getName = function() {
    return this.name;
}
function Son(name, age) {
    Parent.call(this, name);
    this.age = age;
}

//因为继承的本质是 Son.__proto__ == Parent && Son.prototype.__proto__ == Parent.prototype
// Reflect.setPrototypeOf = function(obj, proto) { obj.__proto__ = proto; return obj}
// Reflect.setPrototypeOf(Son, Parent);
// Reflect.setPrototypeOf(Son.prototype, Parent.prototype);
// if(!!Reflect) { //需要判断 Reflect的兼容性
//     Reflect.setPrototypeOf(Son, Parent);
//     Reflect.setPrototypeOf(Son.prototype, Parent.prototype)
// } else {
//     Son.__proto__ = Parent;
//     Son.prototype.__proto__ = Parent.prototype;
// }
//也可以使用Object.create
Son.prototype = Object.create(Parent.prototype);
Son.prototype.constructor = Son
Son.prototype.getAge = function () {
    return this.age
}
const son = new Son('james', 35);
console.log(son.getName() + '--' + son.getAge())
console.log(Son.prototype.constructor === Son)
console 命令行工具 X clear

                    
>
console