// 新写法, 直观,简洁,适合不需要传参的类 class Person1 { name = 'lily' age = 20 speak() { console.log(`my name is ${this.name}, I am ${this.age} years old`) } } // 可以传参,但是要多写一个constructor class Person2 { constructor(name, age) { this.name = name this.age = age } speak() { console.log(`my name is ${this.name}, I am ${this.age} years old`) } } const person1 = new Person1() const person2 = new Person2('kuohao', 22) person1.speak() person2.speak()