vdegenne
vdegenne

Reputation: 13270

how to pass a function requiring parameters as another's function arguments?

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 ?

Upvotes: 0

Views: 51

Answers (1)

Márcio Gonzalez
Márcio Gonzalez

Reputation: 1040

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.

Upvotes: 1

Related Questions