1var obj = {
2 value: '',
3 letMeKnow() {
4 console.log(`The variable has changed to ${this.testVar}`);
5 },
6 get testVar() {
7 return this.value;
8 },
9 set testVar(value) {
10 this.value = value;
11 this.letMeKnow();
12 }
13}
14
15console.log(obj.testVar)
16
17obj.testVar = 5;
18console.log(obj.testVar)
19
20obj.testVar = 15;
21console.log(obj.testVar)