0

I am having the following object:

obj = 
config {
    commonId: "id-goes-here",
    option1 : {
        value : "",
        link : "some-link/" + commonId should go here
    },
    option2 : {
        value : "",
        link : "some--other-link/" + commonId should go here
    },
    option3 : {
        value : "",
        link : "link/" + commonId should go here
    },
}

How would one refer to the commonId that's declared within the same object ? I don't think repeating the same ID is good practice..

Joe Clay
  • 33,401
  • 4
  • 85
  • 85
Laurens Mäkel
  • 815
  • 2
  • 12
  • 29
  • the way you are trying i dont think this will work. Instead you can store the id in some variable and then use to set the attributes. – Manish Aug 10 '17 at 10:35
  • Issue you face is that properties of an object don't exist until the whole object is compiled. You can't directly reference another property in value unless it is a function call – charlietfl Aug 10 '17 at 10:38
  • _“I don't think repeating the same ID is good practice”_ - well then why are you trying to append the same value in multiple places to begin with? Why not let your processing logic handle this, and use the _partial_ `link` value of the option and _append_ `commonId` in the place where you eventually need the whole value? – CBroe Aug 10 '17 at 10:40
  • Well I fixed it by placing a variable string above containing the ID. – Laurens Mäkel Aug 10 '17 at 10:51

0 Answers0