Forum Discussion

Vallalarasu_P's avatar
Frequent Contributor
5 years ago

Javascript Unit references - UseUnit or Modules.export?

In JavaScript Project, For Reference of the units which methods is better to use either USEUNIT or Modules.Export. or Require.?


Please point out the advantages and drawbacks of each methods.


Also, Will //USEUNIT get depreceated in future for JavaScript alone, As it is mentioned as Legacy support.


thanks in advance


2 Replies

  • tristaanogre's avatar
    Esteemed Contributor

    Starting with your last question first.


    "Legacy" support refers to the need for supporting USEUNIT for any projects converted from JScript to JavaScript.  JScript does not support the modules.export/require in TestComplete so any code units written in JScript use //USEUNIT.  In converting, that needs to be supported so as to maintain a compatability.


    As for which is better....  I think, personally, the native JavaScript Modules.Export/Require is preferred.  It uses more of the main engine and doesn't rely on TestComplete specifics.  You could easily write JavaScript code in some other IDE and then use it in TestComplete if necessary using that methodology and vice-versa (with caveats, of course, for any TestComplete specific objects and methods).


    However... neither one is listed as "preferred".  There are limitations and things that are different, all documented at

    • cunderw's avatar
      Community Hero

      I would personally use the modules.exports, it allows for better control of what functions other script units have access too.