I have a class like the following.
class ColorTest {
#light;
constructor() {
this.#light = {
color: "Purple",
brightness: "Bright",
}
this.colors = {
first: {
get color() {
return this.light.color;
},
get brightness() {
return this.light.brightness;
}
},
second: {
color: "",
brightness: ""
}
}
}
get light() {
return this.#light;
}
set light(value) {
// Do stuff
}
}
let colorTest = ColorTest();
let firstColor = colorTest.colors.first.color;
When I try to run this code it gives me an error message that says "TypeError: Cannot read property 'color' of undefined", with a reference to the line that says return this.light.color;
. No matter what I try, I cannot figure out how to get around this. Any suggestions?