Typescript学习系列---《类》

class Person {
    name: string; //属性 前面省略了public关键字
    constructor(n: string) { // 构造函数, 实例化类的时候触发的方法
        this.name = n;
    }
    run():void {
        console.log(this.name);
    }
}
var p = new Person('Jack');
p.run();

发布了91 篇原创文章 · 获赞 18 · 访问量 3187

猜你喜欢

转载自blog.csdn.net/A_bad_horse/article/details/105025652