ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 1.创建一个对象 ~~~ class Person{ constructor(name,age){ this.name = name; this.age = age; } sayName(){ console.log(this.name) } } let cheng = new Person("cheng",18); cheng.sayName(); ~~~ ## 2.extends继承 ~~~ class Person{ constructor(name,age){ this.name = name; this.age = age; } sayName(){ console.log(this.name) } } class Teacher extends Person{ constructor(name,age,skill){ super(name,age); this.skill = skill; } saySkill(){ console.log(this.skill); } } let cheng = new Teacher("cheng",18,"HTML5"); cheng.saySkill(); ~~~