How can I get JavaScript to 'unroll' a variable number of parameters?

javascript

Solution

Something like this:

function b(func) {
    func.apply(null, [].slice.call(arguments, 1));
}

Problem

For example suppose I have the following two functions ``` function a(param1) { console.log(param1); } function b(func, params) { func(params); } ``` then ``` b(a, 1); ``` prints '1' as expected Now suppose I have an additional function ``` function c(param1, param2) { console.log(param1, param2); } ``` Is there some way of doing something similar to ``` b(a, 1); ``` Except feeding in two parameters? Something like the following ``` b(c, [2, 3]); ``` Where the [2, 3] arrray is unrolled into individual parameters

Original source