所以我试图制作一个模块化系统,到目前为止除了获取变量/对象属性这是我正在做的事情
var obj1 = function(){
this.objList = [];
var obj2 = function(){
this.var = 0;
}
this.createObj = function(){
var ent = new obj2();
//newId would change with a for loop counter too lazy to write it
this.objList[newId] = ent;
}
this.newFuncProp = function(){
console(this.var);
}
}
var objClass = new obj1();
objClass.createObj();
objClass.objList[newId].constructor.prop = objClass.newFuncProp;
objClass.objList[newId].prop();
代码末尾的调用将记录到控制台NaN,如果我记录了它,它将仅记录该函数。我如何正确访问this.var?