Because he bind's ed. What you have to do is:
When adding:
let contextMenu = window.document.getElementById('contentAreaContextMenu');
if (contextMenu) {
this.contextPopupShowingBound = this.contextPopupShowing.bind(this);
contextMenu.addEventListener('popupshowing',
this.contextPopupShowingBinded, false);
console.log(this.contextPopupShowing.toString());
}
And then disabling the addon
console.log(this.contextPopupShowing.toString()); // same as above
this.contextMenu.removeEventListener('popupshowing',
this.contextPopupShowingBound, false);
// just showing that 'this' is working
this.contextMenu.removeChild(this.menuitem);
Finally...
contextPopupShowing: function() {
console.log('contextPopupShowing called');
},
You cannot use bindin removeEventListener, I'm sure.
See this great topic on the topic: Removing an Event Listener That Was Added with Binding
source
share