Forum Discussion

soda's avatar
soda
Contributor
13 years ago

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.

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    JScript is different than javascript.  So, I'm not sure if what you're looking at doing is supported in JScript.  Someone with better knowledge will be able to tell you more.
  • soda's avatar
    soda
    Contributor
    I thought[at one time at least] JScript had the same features as JavaScript except MS added additional features to JScript?  In any case, I determined that it is possible to pass a function to another function that is in another .sj file.  It took me a while to track down why an exception was being thrown, and that was why I posted, but it was a typo in the end.  Argh.



    Short answer to my own question: Yes.