3

Im totally new in JS. Could someone help me please? I need to prepare some objects atributes which depends on other objects attributes

How can I achive that?

I tried that solution:

var Photo =  {
      current: {
        coordinates: "2208,1922",
        name: "current"
      },
      start: {
        coordinates: '2408,1822',
        name: 'start',
        newCoordinates: Photo.current.coordinates
        }
  };

I'm getting an error:

module initialization error: TypeError
Anna K
  • 1,666
  • 4
  • 23
  • 47

2 Answers2

3

var current = {
        coordinates: "2208,1922",
        name: "current"
      }

var Photo =  {
      current: current,
      start: {
        coordinates: '2408,1822',
        name: 'start',
        newCoordinates: current.coordinates
        }
  };
  
  console.log(Photo);
Rohit Bajaniya
  • 41
  • 1
  • 10
2

You just need to wait for the object to be initialized, then you can grab that property. See this code:

var Photo =  {
      current: {
        coordinates: "2208,1922",
        name: "current"
      },
      start: {
        coordinates: '2408,1822',
        name: 'start'
        }
  };
  
  Photo.start.newCoordinates = Photo.current.coordinates;   // 2208,1922
freginold
  • 3,946
  • 3
  • 13
  • 28