Forum Discussion

Philip_Baird's avatar
Philip_Baird
Community Expert
12 years ago

NameSpace and Module patterns using JScript


I have just started working on a Test Complete JScript project (complete novice) and I am looking at introducing proper NameSpace and Module (as prescribed by idiomatic.js) patterns as it is currently descending into spaghetti code.


 


As a proof of concept I have created the following Script Units:


 


NameSpace.sj which contains


 


/**


  Define NameSpaces


  -TODO- Use correct pattern


*/


var com = {};


com.testcompany = {};


com.testcompany.testcomplete = {};


com.testcompany.testcomplete.utils = {};


 


 


MyModule.sj which contains:


 


//USEUNIT NameSpace


 


(function( namespace ) {


 


  var TestModule = (function() {


    // Private Members


    var priv = "I am private";


    


    // Public Members


    return {


      meth : function() {


        return priv;


      }


    };


  })();


 


  namespace.TestModule = TestModule;


 


})(com.testcompany.testcomplete.utils);


 


 


and finally Unit1.sj which contatins:


 


//USEUNIT MyModule


 


// Alias namespace


var testModule = com.testcompany.testcomplete.utils.TestModule;


 


test = function() {


  Log.Message(testModule.meth());


}


 


So far this all works as expected but I was wondering if someone who had experience using similar patterns in Test Complete could answer the following for me:


 


1. Is this actually a good way to develop in Test Complete?


2. Are there any considerations regarding load order?


3. Are there any memory considerations?


4. Any other considerations you can think of would be useful

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Hi Benjamin, yes, I did further work on this, and did in fact implement a Namespace implementation using patterns similar to those used by Yahoo. This was when I was new to Test Complete and didn't have much experience with the runtime.


     


    A few months later, after having had more experience with Test Complete, I removed it completely (chalk it up as a learning experience).


     


    The reason why?


     


    1. Script Units run in isolation, there is no real need for Namespace separation


    2. Code buried in a Namespace is not available in the intellisense, this had a major impact on usability for other developers


    3. Exception handling was a nightmare due to Exceptions not being propogated


    4. Script Extensions provide a alternative to JScript Modules, the trick is to understand their limitations and learn to use them correctly


    5. The CLR Bridge allows access to custom .Net libraries which, to be honest, kick JScript to the curb


     


    I only use JScript as the glue to hold everything together, contrary to others, I use as little native JScript functionality as possible, I will always use built in or custom .Net libraries if possible and only turn to JScript features if no alternative is available.


     


    The thing I have learnt is to not try and force Browser app dev patterns in Test Complete, it is it's own beast and a lot of the design patterns used in Browser dev simply do not fit.


     


    Regards,


    Phil Baird

  • Hello,



    Did you do any further investigation in this field? If yes, what was your impressions about usability, development?