// function Father(name) {
// this.name = name;
// this.color = ['red']
// }
// function Son(age) {
// this.age = age;
// }
// // 通过原型继承
// Son.prototype = Father.prototype
// const s = new Son(18)
// console.log(s)
// function Father(name) {
// this.name = name;
// this.color = ['red']
// }
// function Son(age) {
// // 通过构造函数继承
// Father.call(this, '张三');
// this.age = age;
// }
// const s = new Son(18)
// console.log(s, s.name)
// function Father(name) {
// this.name = name;
// this.color = ['red']
// }
// Father.prototype.getName = function() {
// console.log('zz')
// }
// function Son(age) {
// Father.call(this, '张三');
// this.age = age;
// }
// // 组合继承
// Son.prototype = new Father()
// const s = new Son(18)
// console.log(s, s.name)
// 寄生式继承
// function createObj(origin) {
// const clone = Object.create(origin);
// clone.getName = function() {
// console.log(this.name)
// }
// return clone;
// }
// const p = {
// name: 'cc',
// show() {
// console.log('show')
// }
// }
// const pp = createObj(p)
// pp.show()
// pp.getName()
// 寄生式组合继承
function inheritPrototype(sup, sub) {
const o = Object.create(sup.prototype);
o.construtor = sub;
sub.prototype = o;
}
function Father(name) {
this.name = name;
this.color = ['red']
}
Father.prototype.getName = function() {
console.log('zz')
}
function Son(age, name) {
Father.call(this, name);
this.age = age;
}
inheritPrototype(Father, Son);
const s = new Son(18, '0.0')
s.getName()
console.log(s.age, s.name)
console