下面是一些JavaScript代码,我有:基于自己的变量创建Javascript对象?
var screenWidth = 1280;
var screenHeight = 720;
var shapeComtainer = {
name : "bender",
offsetX : 100,
offsetY : 100,
width : screenWidth - 2*offsetX,
height : screenHeight - 2*offsetY,
};
我越来越OFFSETX和OFFSETY没有定义的错误。这是我正在计算宽度和高度的线。问题是我的宽度和高度取决于同一对象内的其他变量。
是否有一个更好/正确的方法来让JavaScript对象表示诸如偏移量和大小信息之类的信息?
可能重复的[JavaScript:访问自己的对象属性里面的数组文字](http://stackoverflow.com/questions/3330686/javascript-access-own-object-property-inside-array-literal)(忽略数组文字部分,这是同样的问题)。 – 2012-03-08 21:56:23
这与JSON无关。 – 2012-03-08 21:56:50
同样重复http://stackoverflow.com/questions/3392033/referencing-other-properties-in-object-creation,http://stackoverflow.com/questions/7433395/object-referencing-its-own-property- on-initilization,http://stackoverflow.com/questions/4616202/self-references-in-object-literal-declarations – 2012-03-08 21:59:59