如何传递一个需要参数作为另一个函数参数的函数?

时间:2022-04-27 18:02:29

I have this function,

我有这个功能,

function foo (foo1, foo2) {
   ...
}

I need to pass it as an argument of another function :

我需要将它作为另一个函数的参数传递:

caller(foo);

how is the most proper way to pass the arguments of foo in the caller function ?

如何在调用函数中传递foo的参数是最正确的方法?

1 个解决方案

#1


Did you try something like this?

你尝试过这样的事吗?

function internalMethod(a, b) {
   console.log(a);
   console.log(b);
}

function externalMethod (method) {
    method (arguments[1], arguments[2]);
}

externalMethod (internalMethod, "First argument", "Second argument");

Hope it help.

希望它有所帮助。

#1


Did you try something like this?

你尝试过这样的事吗?

function internalMethod(a, b) {
   console.log(a);
   console.log(b);
}

function externalMethod (method) {
    method (arguments[1], arguments[2]);
}

externalMethod (internalMethod, "First argument", "Second argument");

Hope it help.

希望它有所帮助。