我想将函数“testMath”的名称作为字符串传递给名为“runTest”的包装函数作为参数。然后在'runTest'中我会调用传递的函数。我这样做的原因是因为我们有一组通用数据,无论测试如何,它们都会填充到变量中,然后可以根据用户想要测试的任何内容调用特定的测试。我正在尝试使用 javascript/jquery 来做到这一点。实际上,该函数要复杂得多,包括一些 ajax 调用,但这种情况突出了基本挑战。
//This is the wrapper that will trigger all the tests to be ran
function performMytests(){
runTest("testMath"); //This is the area that I'm not sure is possible
runTest("someOtherTestFunction");
runTest("someOtherTestFunctionA");
runTest("someOtherTestFunctionB");
}
//This is the reusable function that will load generic data and call the function
function runTest(myFunction){
var testQuery = "ABC";
var testResult = "EFG";
myFunction(testQuery, testResult); //This is the area that I'm not sure is possible
}
//each project will have unique tests that they can configure using the standardized data
function testMath(strTestA, strTestB){
//perform some test
}