es6原型

es3,es5原型

function Animal(){
  this.name=function(){
    alert('Aaa')
  }
}
function Dag(){
  this.bark=function(){
    alert('Ha shiqi')
  }
}
Dag.prototype=new Animal()
var hashiqi=new Dag()
hashiqi.bark()
hashiqi.name()

es6原型

{
  class Animal {
    constructor(name) {
      this.name=name
    }
    eat(){
      alert(this.name+'eat')
    }

  }
  class Dog extends Animal{
    constructor(name){
      super(name)
      this.name=name
    }
    say(){
      alert(this.name+'say')
    }
  }
  const dog=new Dog('hasiqi')
  dog.say()
}

猜你喜欢

转载自blog.csdn.net/qq_28008615/article/details/80510110
ES6