Hi,
I am currently looking into converting our project from jscript to javascript and I am hitting a seemingly simple problem. I cannot seem to call/access functions or variables defined in another script unit. In our current implementation I am able to say ScriptUnit.functionX() from any other script unit. I cannot seem to get this working with javascript, and seems very simple....
Hi Ryan,
You need to add 'require' statements to each of the modules (scripts) that you wish to use another module's commands such like the following:-
var GlobalValues = require("GlobalValues");
Access to components within GlobalValues is then possible implementing the period notation such like:
GlobalValues.[COMPONENT TO CALL]
In addition, the module that contains re-usable items will need to 'export' their interfaces such like:
module.exports.gTiming = true;
Hope this helps?
is there any way to add a full class to the exports. say i have a class called Constants, and I want these to be available for use everywhere, do i need to add a module.exports.blah to everything?
I'm afraid so. Though the best approach here would be to configure the values as properties within an object which would mean you would only have to export the object not each value/global.
BTW, in addition to the export statement I believe the 'USEUNIT ' command carries across from JScript.
I prefer USEUNIT as it is the easiest to implement.
so you can still use "//USEUNIT Blah" with Javascript? are you still hindered by CircularReferences using this approach?
I think that, since it's a different dll, it MIGHT not be restricted in JavaScript. You can try it but if you're not already using circular references, then it's no loss if you continue in that vein
Subject | Author | Latest Post |
---|---|---|