我想将一个函数绑定(bind)到一个事件,但我想更改调用该函数的上下文
function Foo(){
t : "123",
bar: function(){
// I am here
$('#selector').bind('click' this.foo);
}
,
foo: function(){
//I want when to be able to use the current object here by this
//this.t should be 123 and this.bar should call the above function
}
}
最佳答案
您可以使用 jQuery.proxy :
$('#selector').bind('click', $.proxy(this.foo,this) );
关于javascript - jQuery 绑定(bind)一个不同的 this,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11066511/