我试图通过评估在表达一个特定函数调用来模拟在JavaScript懒评价一个特定的功能,同时使其他功能原样。是否可以在不评估其他函数的情况下评估表达式中的一个函数(以使表达式中的所有其他函数调用保持原样)?评估在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";
你必须做解析,在这里,或使用替代品。 – 2013-05-01 18:04:51
可以解析参数1串 – 2013-05-01 18:05:04
@MikeHometchko哪个字符串是“参数1字符串”? – 2013-05-01 18:05:25