【发布时间】:2015-04-29 12:26:25
【问题描述】:
如果我的代码结构如下:
Thing.prototype = {
doSomething: function() {
$(selector).click(this.handleClick.bind(null, this));
},
handleClick: function(self, event) {
console.log(this); //Window
console.log(self); //Thing
}
}
如何将 Thing this 上下文绑定到 self 参数并仍然保持 this 对象的行为,就好像使用 bind 方法没有绑定任何参数一样?
注意:我知道我可以绑定 this 并使用 e.originalEvent.target 来获得我想要的行为,但我只是好奇是否还有其他方法
我希望我能完成我想要实现的目标,如果有任何不明确的地方,请发表评论。
【问题讨论】:
-
不,我想使用处理程序的原始
this(被点击的元素),但将 Thingthis传递给 self 变量。
标签: javascript jquery prototype