指定Person.name只能在类内部访问,但方法Person.getName()可以在任何地方访问:
class Person {
@(7) name: string;
public constructor(name: string) {
this.name = name;
}
@(6) getName(): string {
return this.name;
}
}
class Person {
private name: string;
public constructor(name: string) {
this.name = name;
}
public getName(): string {
return this.name;
}
}