我正在尝试将对象函数的函数指针存储在数组中。但是当我想访问函数中对象的另一个属性时,它给了我问题。有人可以解决这个问题或给我一个解决方法的想法吗?
function O(){
this.name="hello";
this.f=function(){
alert(this.name);//why does "this" refer to the array arr rather than the object?
};
this.arr=[];
this.arr["x"]=this.f;
}
var d=new O();
d.arr["x"]();