我想在原型链上创建一个设置对象,作为我的应用程序的查找。我试过这个:
var d9l = {};
d9l.aMethod = function() {
//fails here with Cannot read property 'dimension1' of undefined
alert(this.anObject.dimension1);
};
d9l.aMethod.prototype.anObject = {
dimension1 : "x1",
dimension2 : "y1"
};
var testing = d9l.aMethod();
但我只是在构造函数中无法读取未定义的属性'dimension1' 。不能将原型定义为对象吗?