TypeScript 四.类
类的创建和使用
class Person {
//成员变量
name: string;
age: number;
//构造函数
constructor(myName: string, myAge: number) {
this.name = myName;
this.age = myAge;
}
//成员方法
fun() {
//方法体
console.log("我的姓名" + this.name);
console.log("我的年龄" + this.age);
}
}
let person = new Person('xioaming',18)