class Person{

    constructor(name,age){

    this.name = name;

    this.age = age;

    }

    showName(){

    alert(this.name)

    }

};

var p2 = new Person('张三',20);
p2.showName();

使用关键字class创建类

使用new关键字创建对象

相关文章:

  • 2021-06-25
  • 2021-06-28
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2021-07-06
相关资源
相似解决方案