I have a class constructor with a nested object structure. Each level has a property x.
this.x > this.a.x > this.a.b.x
I want this.a.b.x to point to the value of this.a.x, but it instead points to this.x.
class Example {
constructor() {
this.x = 0;
this.a = {
x: this.x + 5,
b: {
x: this.x // I want this to equal 5
}
}
}
}
const ex = new Example();
console.log(ex.x) // 0
console.log(ex.a.x) // 5
console.log(ex.a.b.x) // 0 <-- I want this to be 5
How can I change the this reference in this.a.b to point to this.a rather than this??