📜  初始化类定义 javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:47.359000             🧑  作者: Mango

代码示例1
// Initializing a class definition
class Hero {
    constructor(name, level) {
        this.name = name;
        this.level = level;
    }
      
       // Adding a method to the constructor
    greet() {
        return `${this.name} says hello.`;
    }
}