Forum Discussion
Philip_Baird
12 years agoCommunity Expert
Hi Scott, something else that you may or may not be aware of that is related to the Exception problem is that because JScript Script Units run in their own sandbox, augmentation of native JScript object only apply to the Script Unit they are defined in.
E.g. The version of JScript in Test Complete has no Array::indexOf() function, therefore I augmented the Array prototype in a common Script Unit as such
// Augment JScript Array with an indexOf function
Array.prototype.indexOf = function( item )
{
for ( var j = 0; j < this.length; j++ )
{
if ( ( j in this ) && ( this[ j ] == item) ) return j;
}
return -1;
};
Unfortunately, this augmentation only applies in the defining Script Unit so Arrays created in other Script Units do not have the indexOf() function
To work around this, the Script Unit needs to supply a factory function which returns an instance of the augmented Array to other Script Units, as such
// Factory function to create instances of the augemented Array
function arrayFactory( init ){
if( init ){
return new Array().concat( init );
}
return new Array()
}
Anyway, you may already be aware of this but it is gotcha in a similar vein to Exception handling.
Related Content
- 14 years ago
- 13 years ago
- 6 years ago
- 10 years ago
Recent Discussions
- 5 days ago
- 5 days ago