【发布时间】:2016-09-19 15:32:27
【问题描述】:
function foo(){
var a = 1;
this.b = 2;
this.c = function(){
alert(a);
alert(this.b);
$('.ei').each(function(){
alert(a);
alert(this.b);//undefined <-- i need this to be update to 3
});
}
}
var obj = new foo;
obj.b = 3; //update this property before call method
obj.c();
我有一个包含 jquery each() 的方法,我尝试访问该对象的属性,但我得到未定义
我需要这个属性能够更新
有人知道怎么做吗?
【问题讨论】:
-
thisinsideeach将引用集合中的当前元素。将this缓存到that并使用that.b。
标签: javascript jquery oop