我有2个对象的对象:
o = {
center : { x:1, y:1 },
startPosition : {x:center.x, y:center.y}
}
当然我有一个错误:
ReferenceError: center is not defined
如何在startPosition中获取中心值?
答案 0 :(得分:2)
试试这个
o = {
center : { x:1, y:1 }
}
o.startPosition = {x:o.center.x, y:o.center.y}
答案 1 :(得分:1)
o = {};
o.center = { x:1, y:1 };
o.startPosition = { x:o.center.x, y:o.center.y };
答案 2 :(得分:1)
您可以尝试:
var o = {
center: {
'x':1,
'y':1
}
};
o.startPosition = {
'x': o.center.x,
'y': o.center.y
};
console.log(o.startPosition.y);