我来自C#背景。我的大部分课程都设计为不可变的。我想知道是否使用私有构造函数变量和公共getter访问TypeScript类中的数据是一种很好的做法。TypeScript类的私有构造函数变量和公共获得者
例如:
class UnitType {
constructor(private code: string, private name: string, private unitType: string) {
}
get Code(): string {
return this.code;
}
get Name(): string {
return this.name;
}
get UnitType(): string
return this.unitType;
}
我似乎不能找到的打字原稿代码任何例子如上。我错过了什么吗?
没关系,但不要利用你的干将或者他们会像类名有经验的开发者。 'private _code'和'get code()'会更典型。 – JohnnyHK
这是C#dev的习惯... –
@JohnnyHK了解。像Harry说的那样,C#最佳实践是将资产资本化。但是,当在罗马...... – cruzan