JavaScript Controlled Class Properties (getter and setter)
JS
S
JavaScriptExample of using getters and setters to control W/R access to class properties, in the example we have a boolean property.
1 // Boolean Property
2 public get loggedIn(): boolean {
3 return (localStorage.getItem('access_token') !== null);
4 }
5
6 public set loggedIn(): boolean {
7 return (localStorage.getItem('access_token') !== null);
8 }Created on 12/4/2018