You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12 lines
328 B

2 years ago
  1. class Person {
  2. age: number
  3. gender: string
  4. constructor(age:number, gender: string) {
  5. // this.age 指的是最上面的实例属性,age 指的是构造函数 constructor 中的参数age
  6. this.age = age
  7. this.gender = gender
  8. }
  9. }
  10. const p = new Person(18, '男')
  11. console.log(p.age, p.gender)