I have this object:
const obj = {
  thing: 5,
  layer: {
    otherThing: obj.thing - 2
  }
}
error:
ReferenceError: Cannot access 'obj' before initialization
I tried to use this but it didn't work as expected.
I have this object:
const obj = {
  thing: 5,
  layer: {
    otherThing: obj.thing - 2
  }
}
error:
ReferenceError: Cannot access 'obj' before initialization
I tried to use this but it didn't work as expected.
 
    
    This is not something you can do in JavaScript. But you have two possible alternatives here:
1)
    const obj = {thing: 5, layer: {}};
    obj.layer.otherThing = obj.thing - 2;
2) getters
    const obj = {
       thing: 5,
       layer: {
          get otherThing(){obj.thing - 2}
       }
    }
 
    
    