ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 示例 ## hello world old: ``` function Student(name) { this.name = name; } Student.prototype.hello = function () { alert('Hello, ' + this.name + '!'); } ``` new: ``` export class Student { constructor(name) { this.name = name; } hello() { alert('Hello, ' + this.name + '!'); } } ``` 调用方式都是一样 ``` // 导入 import {Student} from "student.js" var student = new Student("word"); student.hello() ``` ### 传入对象 ``` export class person{ constructor({name,age}) { this.name=name this.age=age } echo(){ return this.name+this.age } } ``` 调用 ``` import {person} from "person.js"; let good1 =new person({name:"cpj",age:123}); ```