Forum Discussion

ryan_perneel's avatar
ryan_perneel
Contributor
8 years ago

Javascript Samples

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....

6 Replies

  • RichLC's avatar
    RichLC
    New Contributor

    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?

    • ryan_perneel's avatar
      ryan_perneel
      Contributor

      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?

       

       

      • RichLC's avatar
        RichLC
        New Contributor

        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.