构造函数形式的继承 12345678910111213 function Animal(){ this.eat=function(){ console.log('animal eat') }}function Dog(){ this.bark=function(){ console.log('Dog bark') }}Dog.prototype=new Animal()var dog1=new Dog()dog1.eat() class继承 12345678910111213141516171819 class Animal{ constructor(name){ this.name=name } eat(){ console.log(this.name+'eat') }}class Dog extends Animal(){ constructor(name,age){ super(name)//继承父类 this.age=age } say(){ console.log(this.name+'say') }}const dog=new Dog('哈士奇')dog.say() 拷贝继承 1 //高程6.3继承 赞微海报分享
近期评论