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.
 
 
 
 
 

13 lines
328 B

class Person {
age: number
gender: string
constructor(age:number, gender: string) {
// this.age 指的是最上面的实例属性,age 指的是构造函数 constructor 中的参数age
this.age = age
this.gender = gender
}
}
const p = new Person(18, '男')
console.log(p.age, p.gender)