我试图通过评估表达式中的一个特定函数调用来模仿 JavaScript 中的惰性求值,同时保持其他函数不变。是否可以只计算表达式中的一个函数而不计算其他函数(以便表达式中的所有其他函数调用保持原样)?
这是我要实现的功能:
function evaluateSpecificFunction(theExpression, functionsToEvaluate){
//Evaluate one specific function in the expression, and return the new expression, with one specific function being evaluated
}
例如:
evaluateSpecificFunction("addTwoNumbers(1, 2) + getGreatestPrimeFactor(10)", addTwoNumbers);
//This should return "3 + getGreatestPrimeFactor(10)", since only one of the functions is being evaluated
evaluateSpecificFunction("addTwoNumbers(1, 2) + getGreatestPrimeFactor(10)", getGreatestPrimeFactor);
//This should return "addTwoNumbers(1, 2) + 5";