TypeScript——类

对类的使用:

class Person {
    name:string;
    age: number;
    constructor(name:string, age:number){
        this.name = name;
        this.age = age;
    }
    print () {
        return this.name + ':' + this.age;
    }
}
var p = new Person("小宝", 19);
p.print(); // "小宝:19"

你可能感兴趣的:(TypeScript——类)