他の関数はそのままにして、式で特定の関数呼び出しを評価することにより、JavaScript で遅延評価を模倣しようとしています。他の関数を評価せずに、式内の 1 つの関数だけを評価することは可能ですか (そのため、式内の他のすべての関数呼び出しはそのまま残されます)。
実装しようとしている機能は次のとおりです。
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";