【发布时间】:2022-06-15 00:32:06
【问题描述】:
编写使用 Typescript 和 Webstorm 作为 IDE 的 Angular 应用程序。
最初,编写的代码是
class MyComponent implements OnInit {
/**
* Docstring explaining isProcessing
*/
isProcessing = false;
/**
* Docstring after a blank line brake
*/
data: any;
constructor(
private myService: MyService
) {}
ngOnit() {
console.log('Angular init');
}
get data() {
return this.data;
}
private setData(data) {
this.data = data;
}
getData() {
return this.data;
}
}
在提交更改时,我选择了以下选项
之后代码改为
class MyComponent implements OnInit {
/**
* Docstring after a blank line brake
*/
data: any;
/** // Blank line removed
* Docstring explaining isProcessing
*/
isProcessing = false;
constructor(
private myService: MyService
) { // constructor empty body brackets
}
get data() { // getter moved above ngOnit
return this.data;
}
ngOnit() {
console.log('Angular init');
}
getData() {
return this.data;
}
private setData(data) { // private methods moved to bottom
this.data = data;
}
}
现在我必须向我的团队解释为什么会发生这种情况,以及在属性或方法的间距和排列方面应遵循哪些准则?
尝试查看 typescript 最佳实践 (https://google.github.io/styleguide/tsguide.html),但没有找到关于上述内容的任何内容。
【问题讨论】:
标签: typescript