2017-04-12 41 views
1

在JS中我是全新的。请有人帮助我吗?我需要准备一些对象属性,这取决于其他对象的属性如何从一个属性访问其他对象atributins

我该如何存档?

我试过了解决方案:

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

我得到一个错误:

module initialization error: TypeError 

回答

2

你只需要等待初始化的对象,那么你可以抓住该属性。看到这个代码:

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

1

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

 
var Photo = { 
 
     current: current, 
 
     start: { 
 
     coordinates: '2408,1822', 
 
     name: 'start', 
 
     newCoordinates: current.coordinates 
 
     } 
 
    }; 
 
    
 
    console.log(Photo);