Hi Howie, in order to approximate classes in JScript, I have used
Dean Edwards Base.js which, in my view, simplifies defining classes as well as providing an extend() function which makes inheritance a breeze, e.g.
A base Class:
var Thing = Base.extend( {
constructor: function() {
this.Items = new Array( "10", "20", "30" );
},
Items: null,
Find: function( itemToFind ) {
for ( var j = 0; j < this.Items.length; j++ )
if ( this.Items[ j ] === itemToFind ) {
return j;
}
return -1;
}
} );
A sub class:
var It = Thing.extend( {
constructor: function( name ) {
this.base();
this.Name = name;
},
Name: null,
GetName: function() {
return this.Name || "I am nameless";
}
} );
In order to import the Base.js file into Test Complete, I simply changed the extension from .js to .sj and added as an Existing Item.
This does, of course, need the appropriate //USEUNIT statement to include the Script Unit containing Base at the head of the Script Unit in which the classes are defined
I have used Base.js for the following reasons:
It is easy to use
It is standalone where other, similar class libraries are part of a larger library such as JQuery