在子类的构造函数中执行父类的构造函数,并且对其绑定子类的this
function Parent(name){
this.name=[name]
}
Parent.prototype.getName=function(){
return this.name
}
function Child(){
Parent.call(this,'rose')
}
const child1=new Child()
const child2=new Child()
child1.name[0]='jisoo'
console.log(child1.name)//jisoo
console.log(child2.name)//rose//解决了指向同一个实例的问题
console.log(child2.getName())//报错,不能继承父类原型上的方法和属性