我的主要问题是,接受什么类型的数据功能参数? 我将通过比较作为参数,例如
Function test(a) //where A is a comparison so for example
test("a" == "a")
我正在尝试获取比较表达式而不是结果。
有可能吗?有办法吗?谢谢
我的主要问题是,接受什么类型的数据功能参数? 我将通过比较作为参数,例如
Function test(a) //where A is a comparison so for example
test("a" == "a")
我正在尝试获取比较表达式而不是结果。
有可能吗?有办法吗?谢谢
是的,您可以将函数作为参数传递,并且在JS和其他语言中,传递“谓词”函数是一种很常见的模式。
let isGreaterThan5 = v => v > 5;
let out = [1,3,5,7,9].filter(isGreaterThan5);
console.log(out);
,
是的,有可能:
function isPosible(param) { // Here you define a function
return param;
}
// Below you are executing the function and printing the result
console.log(isPosible("a === a")); // Returns the whole expression
更重要的是要理解您可以将任何表达式作为参数传递给函数,包括但不限于:任何原始类型(字符串,数字,布尔值,未定义,空值等),函数(回调),这些表达式的计算结果类似于您的情况。