【发布时间】:2013-05-15 17:54:40
【问题描述】:
我正在尝试将对象函数的函数指针存储在数组中。但是当我想访问函数中对象的另一个属性时,这给我带来了问题。任何人都可以解决这个问题或给我一个如何工作的想法周围?
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"]();
【问题讨论】:
-
查看我对“this”如何工作的解释:stackoverflow.com/questions/13441307/…
标签: javascript arrays function pointers store