Class类

1、定义类

class Person {
    constructor (obj) {
       this.name =obj.name;
       this.age =obj.age;
    }
    getInfo () {
        console.log(`我是${this.name},今年 ${this.age}岁`);
    }
}
let obj = new Person({name:'vhen',age:'18'});
obj.getInfo()

2、类继承

class Vhen extends Person {
    constructor(obj,sex){
        super(obj)
        this.sex = sex;
    }
    getInfo () {
        console.log(`我是${this.name},今年 ${this.age}岁,性别${this.sex}`);
    }
}
let obj1 = new Vhen({name:'vhen',age:'18'},'男');
obj1.getInfo()

 

posted @ 2017-09-22 18:37  浮生如梦似离殇  阅读(132)  评论(0)    收藏  举报