es6 class定义

class User {
  constructor(name, age) {
    this.name = name
    this.age = age
  }
  static print(age) {
    console.log(this.name + '---' + age)
  }
  sayHello() {
    console.log('hi ' + this.name)
  }
}

user = new User('howhy', 12)
User.print(23)
user.sayHello()

 

posted @ 2024-04-28 17:35  howhy  阅读(1)  评论(0编辑  收藏  举报