问题如下:
var obj = {
name: 'dang',
test:function(){
alert(this.name);
}
};
obj.test(); //这样是可以的
$('.box').click(obj.test); //undefined
js解决:
var obj = {
name: 'dang',
test:function(){
var _this = obj;
alert(_this.name);
}
};
$('.box').click(obj.test);
jQuery解决:
var obj = {
name: 'dang',
test:function(){
alert(this.name);
}
};
$('.box').click($.proxy(obj,'test'));