主页
TypeScript
TypeScript 类
demo_class_readonly
运行 ❯
×
更改方向
保存代码
更改主题
class Person { private readonly name: string; public constructor(name: string) { // name cannot be changed after this initial definition, which has to be either at it's declaration or in the constructor. this.name = name; } public getName(): string { return this.name; } } const person = new Person("Jane"); console.log(person.getName());
Jane