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())
不积跬步,无以至千里;不积小流,无以成江海。