Passing a function as an argument in a javascript function

后端 未结 7 1160
眼角桃花
眼角桃花 2020-12-08 00:25

I was wondering whether this is legal to do. Could I have something like:

function funct(a, foo(x)) {
  ...
}

where a is an ar

7条回答
  •  生来不讨喜
    2020-12-08 01:14

    And what would you like it to achieve? It seems you mixed up a function declaration with a function call.

    If you want to pass another calls result to a function just write funct(some_array, foo(x)). If you want to pass another function itself, then write funct(some_array, foo). You can even pass a so-called anonymous function funct(some_array, function(x) { ... }).

提交回复
热议问题