function Animal(name){
this.colors=['white','black']
this.name = name
this.getName=function(){
return this.name
}
}
function Dog(name,age){
// 构造函数继承
Animal.call(this,name)
this.age = age
}
// 原型链继承
Dog.prototype = new Animal()
const dog1 = new Dog('哈士奇')
console.log(dog1.getName())
console.log(dog1.colors)
const dog2 = new Dog('柴犬')
dog2.colors.push('yellow')
console.log(dog2.colors)
/**
* 构造函数继承解决了原型链继承的引用类型共享和构造函数传参问题
* 问题:getName方法定义在构造函数中,每次创建子类实例都会创建方法
*/