1

Below is the code snippet and i would like to access, propOne.url inside propTwoNested and it should be a property and not a method.

let obj = {
  propOne: {
    url: 'https://www.google.com'
  },
  propTwo: {
    get propTwoNested(){
      return `SITE URL: ${this.propOne.url}` // need to do some computation. Not the exact logic here. 
    }
  },
}

If it try to access it, it throws an error, since this context is different. How to get the value of the parent property inside the getter.

obj.propTwo.propTwoNested // Cannot read properties of undefined (reading 'url')

Is it possible to access it and do not want class based approach.

codermonk
  • 84
  • 6

0 Answers0