Mozilla extension namespace: how to distinguish my function and functions from other packages?

I am developing a Firefox extension (FF) and calling a function when a specific button on FF is pressed. Sometimes FF cannot find my function from my script file, even if it exists. Instead, he searches for it in the browser extension and throws an error.

In general, how to use a namespace in front of my function, which will clearly distinguish it from functions, possibly of the same name in other packages.

For example, there is something like:

<script type="application/javascript" src="chrome://mythird/content/script.js"/>
<statusbar id="status-bar">
    <statusbarpanel id="mythird-statusbarpanel" label="mythird" onclick="chrome://mythird/myalert();"/>
</statusbar>

instead of just:

    <statusbarpanel id="mythird-statusbarpanel" label="mythird" onclick="myalert();"/>
+3
source share
1 answer

. ( ), .

script:

var gYourExtensionName = {};

gYourExtensionName.myalert = function(){/*...*/};

XUL:

<script type="application/javascript" src="chrome://mythird/content/script.js"/>
<statusbar id="status-bar">
    <statusbarpanel id="mythird-statusbarpanel" 
                    label="mythird" 
                    onclick="gYourExtensionName.myalert()" />
</statusbar>

: Firefox:

+3

Source: https://habr.com/ru/post/1777560/


All Articles