Global Javascript module

Hi There,

I need to manage javascript variables and functions common to different UX pages. I’ve tried to group them into one JS file called from all these pages. I’ve tried using <JavaScript File="MyModule.js" /> or var myModule = Require("MyModule.js");, having the JS file included in the .unoproj as a bundle.
But when I want to read one of the “global” variables var a = myModule.oneGlobalVar;, it returns “undefined”.

Please Assist,
Thanks!
Bertrand.

Hi Bertrand,

could you please share some more of your code? Otherwise it’s hard to tell what could be wrong.

Also, keep in mind that for variables to be accessible from outside, you have to export them. Like this:

// MyModule.js
var oneGlobalVar = "some string";

module.exports = {
    oneGlobalVar: oneGlobalVar
};

I was missing the export part. It’s now working smoothly. Thanks a lot for your prompt response, much appreciated!