TypeScript专题-Static和使用技巧

class People {
	static _name: string; 
	print() {
		//alert(this.name);// 编译不通过,doex not exist on type People;声明为static的变量通过类名调用
        return(People._name)
	} 
    constructor(name){
        People._name = name;
    }
}
// let h = new People(); 
// // h.name = "aaa";
// People._name = "aaaa";
// h.print();
//创建类型,为当前类的类型(引用数据类型)
let p:People;
p = new People("aa");
alert(p.print())

  

posted @ 2019-04-09 22:00  icon_sunny  阅读(2083)  评论(0编辑  收藏  举报