In all my extensions, I use namespaces, <extension name>.namespace.
A common javascript module for utility functions, and separate sub-namespaces for the overlay window, options dialog etc.
For example, my browser overlay script -
Code: Select all
if ("undefined" == typeof(PureURL)) {
var PureURL = {};
}
const puPrefBranch = PureURL.Common.prefBranch;
PureURL.Launch={
// All browser window related stuff goes here.
}
window.addEventListener("load", function(){PureURL.Launch.init();},false);
window.addEventListener("unload", PureURL.Launch.cleanup,false);
Why does this happen? Shouldn't there be a new copy of the PureURL.Launch namespace when a new window opens, and only that go out of scope when the window closes? Otherwise what is the difference between using a namespace like this and using a .jsm module (which is expected to remain loaded throughout the existence of the browser process and not dependent on individual windows?)