var dups = new Dups($("#el"))
function Dups($el) {
this.value = 23
$el.on("click", this.onClick)
}
Dups.prototype.onClick = function(){
// usually "this" inside here refers to the instance (Dups)
// but because jquery changes "this", inside here "this" refers to the clicked element
// how can I access the Dups instances "this.value" from here?
alert(this.value) // does not alert 23
}
我的问题是在Dups.prototype.onClick功能。任何想法如何优雅手动访问的DUP实例“这个”比传递其他“这”(点击的元件),因此“该”在prototype.onClick是所希望的一个,像这样:从原型函数内部访问实例而不是通过“this”可能?
...
$el.on("click", function(){this.onClick(this)})
....
它但我想知道是否有更好的方法。
更新我的问题,因为那里是一些逻辑错误 – Hans 2012-03-04 00:59:37