es6 원형

1944 단어 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()
}

좋은 웹페이지 즐겨찾기