1
以下是FF Extension監視瀏覽行爲的代碼。 從processClick
方法處理點擊事件不能訪問trim
方法。無法從使用`this`的事件處理程序中訪問對象的方法
控制檯顯示this.trim
不是功能。 我知道這可能是this
的範圍。
我會很感激任何幫助。
function bbm(doc)
{
this.doc = doc;
this.registerListeners = function() {
this.doc.addEventListener("click", this.processClick, false);
};
this.trim = function(str)
{
return str.replace(/^\s+|\s+$/g, '') ;
};
this.processClick = function(e) {
alert(e.type + " " + this.trim(this.url));
};
};
見http://stackoverflow.com/questions/1338599/addeventlistener-this – 2010-08-12 09:36:14