对。函数引用与任何其他对象引用一样,您可以将它们传递到您的内心。
这是一个更具体的示例:
function foo() { console.log("Hello from foo!");}function caller(f) { // Call the given function f();}function indirectCaller(f) { // Call `caller`, who will in turn call `f` caller(f);}// Do itindirectCaller(foo); // alerts "Hello from foo!"您还可以传递以下参数
foo:
function foo(a, b) { console.log(a + " + " + b + " = " + (a + b));}function caller(f, v1, v2) { // Call the given function f(v1, v2);}function indirectCaller(f, v1, v2) { // Call `caller`, who will in turn call `f` caller(f, v1, v2);}// Do itindirectCaller(foo, 1, 2); // alerts "1 + 2 = 3"


