readonly
JS-0368readonly
11 height = window.innerHeight;
12 width = window.innerWidth;
13
14 constructor(private _shortcut: ShortcutService) {15 this._shortcut.initialize();
16 }
17
Private members are marked as readonly
if they're never modified outside of the constructor.
class Container {
// These member variables could be marked as readonly
private neverModifiedMember = true;
private onlyModifiedInConstructor: number;
public constructor(
onlyModifiedInConstructor: number,
// Private parameter properties can also be marked as readonly
private neverModifiedParameter: string,
) {
this.onlyModifiedInConstructor = onlyModifiedInConstructor;
}
}
class Container {
// Public members might be modified externally
public publicMember: boolean;
// Protected members might be modified by child classes
protected protectedMember: number;
// This is modified later on by the class
private modifiedLater = 'unchanged';
public mutate() {
this.modifiedLater = 'mutated';
}
}