While defining a class, inside the constructor method, I am trying to access the value stored in myKeyOne
for calculating the value that should be stored in myKeyTwo
- however i get an error Uncaught TypeError: Cannot read properties of undefined (reading 'myKeyOne')
I managed to access the value stored in myKeyOne
for calculating the value for myKeyThree
though, which is outside of myObject
class MyClass {
constructor() {
this.myObject = {
myKeyOne: 1,
myKeyTwo: this.myObject.myKeyOne + 1
};
this.myKeyThree = this.myObject.myKeyOne + 1
}
}
My question hence - Is it simply not possible to access the value of one key of an object when calcualting the value of another key of the same object in a class constructor method, or am I doing something wrong here?