What does #
mean as a prefix for Typescript or Javascript class attribute name?
export class MyFacade {
#state: MyState = {
isLoading: true
};
readonly #store = new BehaviorSubject<MyState>(this.#state);
}
What does #
mean as a prefix for Typescript or Javascript class attribute name?
export class MyFacade {
#state: MyState = {
isLoading: true
};
readonly #store = new BehaviorSubject<MyState>(this.#state);
}
2
Answers
The sharp sign
#
means the attribute is private and is only accessible from within the class.Typescript
private
is only checked at compilation when it transpiles to Javascript but the attribute can still be accessed and modified at runtime.myFacade['typescriptPrivateAttribute'] = 'newValue';
Source
in typescript or javascript if you use
#
before class attribute name like#state
or#store
, it means attribute is private to the class, so the attribute will be only accessed or modified within the class itself