Removeeventlistener In Bootstrapped Addon Not Working When Addon Disabled
I have noticed that after disabling a bootstrapped add-on, the removeEventListener does not seem to remove the listener and I can't work out the reason. let contextMenu = window.do
Solution 1:
Because it's bind
'ed. What you gotta do is this:
When adding:
let contextMenu = window.document.getElementById('contentAreaContextMenu');
if (contextMenu) {
this.contextPopupShowingBound = this.contextPopupShowing.bind(this);
contextMenu.addEventListener('popupshowing',
this.contextPopupShowingBinded, false);
// added this to make sure they refer to the same function
console.log(this.contextPopupShowing.toString());
}
And then on disabling the addon
console.log(this.contextPopupShowing.toString()); // same as abovethis.contextMenu.removeEventListener('popupshowing',
this.contextPopupShowingBound, false);
// just showing that 'this' is workingthis.contextMenu.removeChild(this.menuitem);
Finally ...
contextPopupShowing: function() {
// logs even after removeEventListenerconsole.log('contextPopupShowing called');
// more code
},
You cannot use bind
in the removeEventListener
, I'm pretty sure.
See this excellent topic on the subject: Removing event listener which was added with bind
Post a Comment for "Removeeventlistener In Bootstrapped Addon Not Working When Addon Disabled"