soda
14 years agoContributor
Any way to pass function as a parameter to another script?
In javascript, we should be able to pass a function to another function as a parameter. Is it possible in TC to pass a function as a parameter to a function that is in another script?
For example, the first three functions below are in the first script file, and the last function is in a second script file:
//USEUNIT secondscriptfile
var myFirstTest = {
login: function(){
Log.Message('logging in!');
...statements
}
};
var mySecondTest = {
verifyPreferences: function(){
Log.Message('setting prefs');
...statements
}
};
//Run First Test:
driveTests(myFirstTest.login);
//run Second Test
driveTests(mySecondTest.verifyPreferences);
//This Function would be in a different script file
function driveTests(inputFunction){
//run the test
inputFunction();
}
Thanks for any thoughts.
For example, the first three functions below are in the first script file, and the last function is in a second script file:
//USEUNIT secondscriptfile
var myFirstTest = {
login: function(){
Log.Message('logging in!');
...statements
}
};
var mySecondTest = {
verifyPreferences: function(){
Log.Message('setting prefs');
...statements
}
};
//Run First Test:
driveTests(myFirstTest.login);
//run Second Test
driveTests(mySecondTest.verifyPreferences);
//This Function would be in a different script file
function driveTests(inputFunction){
//run the test
inputFunction();
}
Thanks for any thoughts.