下面是一些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