About Lesson
In this JavaScript lesson we are going to learn about JavaScript Getters & Setters, so getters and setter allow us to run the code on the reading and writing of the property.
Now let’s create an example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class Display { constructor(name) { this.name = name; } set name(name) { this._name = name; } get name() { return this._name; } } let display = new Display("John Doe"); console.log(display.name); |