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())

  

原文地址:https://www.cnblogs.com/allyh/p/10680130.html