Forum Discussion

Vallalarasu_P's avatar
Vallalarasu_P
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.

https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-unit/...

 

thanks in advance

Valla

2 Replies

  • tristaanogre's avatar
    tristaanogre
    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 https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-unit/javascript.html#useunit

    • cunderw's avatar
      cunderw
      Community Hero

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