这几天看老外的ts,要转成js 学习了下ts里面的类
用tsc 转换了下
ts 部分
class Doit{
static hello:number=12321;
showHello(){
console.log(Doit.hello)
}
}
js 部分
var Doit = /** @class */ (function () {
function Doit() {
}
Doit.prototype.showHello = function () {
console.log(Doit.hello);
};
Doit.hello = 12321;
return Doit;
}());
所以static的属性,是作用在类本身上的,而不是实例上的
然后js的class ,应该也就是语法糖,参见下面这篇文章
https://www.jianshu.com/p/2aaaacd8bad3
ts 对类的学习,这篇比较好
https://www.cnblogs.com/sghy/p/7742111.html