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()