假设我有一个课程,例如:
class MyClass {
private readonly prop1 = "prop1"
private readonly prop2: string
constructor(
prop2 = "defaultProp2",
private readonly prop3 = "defaultProp3"
) {
this.prop2 = prop2
}
...
}
Run Code Online (Sandbox Code Playgroud)
变量的初始化顺序是什么?
如果进行编译,则ES5可以看到在向下编译代码时事物初始化的顺序(使用本机类时,顺序是一致的)。
var MyClass = /** @class */ (function () {
function MyClass(prop2, prop3) {
if (prop2 === void 0) { prop2 = "defaultProp2"; }
if (prop3 === void 0) { prop3 = "defaultProp3"; }
this.prop3 = prop3;
this.prop1 = "prop1";
this.prop2 = prop2;
}
return MyClass;
}());
Run Code Online (Sandbox Code Playgroud)
因此顺序为:
| 归档时间: |
|
| 查看次数: |
552 次 |
| 最近记录: |