this.progress.click(function(e) { // works
var seek = (e.pageX - this.offsetLeft)/$(this).width();
self_ref[index].seek(seek * self_ref[index].source.duration);
});
this.progress.click($.proxy(function(e) { // doesn't work
var seek = (e.pageX - this.offsetLeft)/$(this).width();
this.seek(seek * this.source.duration);
}, this));
this.offsetLeft
在第一個示例中工作,但不在第二個示例中。我需要$.proxy
,所以我不能擺脫它。一旦上下文在其功能中發生變化,我無法找到一種方法來讓this.offsetLeft
工作。
PS:我不能再回到使用self_ref[index]
因爲我正在處理的擴展。
謝謝,這正是我所期待的。 – 2012-01-16 17:38:23