【发布时间】:2013-03-25 14:23:43
【问题描述】:
我知道这是非常基本的,但是为什么 x 在这个代码块中返回 undefined 呢?有没有办法定义一个属性并立即使用它来设置另一个属性?
var grid = {
x : 75,
y : 75,
location : [grid.x, grid.y],
init : function () {
console.log(grid.location[0]);
}
}
【问题讨论】:
-
如果你需要支持 IE8 或 location: function() { return [this.x, this.y] },。初始化相同。然后在网格之外调用它,你使用
grid.location()