es6中对象的类与继承方法

对于对象,我一直搞不清楚到底是该如何去继承,如何去书写。在熟练es6之后,终于会尝试写出来了。

代码如下:

 1 //我们假定父类为person,子类为man
 2 class person{
 3     constructor(name,age){
 4         this.name=name;
 5         this.age=age
 6     },
 7     say(){
 8           return console.log(this.name+this.age);
 9     }
10 }
12 class man extends person{
13  constructor(name,age , sexy) {
14  super(name,age); // 调用父类的constructor(name, age)
15  this.sexy = sexy;
16  } 
17  say() {
  super.say();
// 调用父类的say()
18 return console.log(this.name);
}
}

 

posted @ 2017-08-18 20:36  MaxLucio  阅读(294)  评论(0编辑  收藏  举报