考虑此错误代码 :
x = {
y : "why",
z : function() {
return y + " zed";
}
}
函数z 不工作 : “ 引用错误: y 未定义 。 ”
是否有办法从函数 z 中访问 y,而不完全指定为 x.y?
我当然可以改写为
x = function() {
var self = this;
this.y = "why";
this.z = function() {
return self.y + " zed";
};
return this;
}();
...但耶稣。