Search code examples
javascriptbind

Function take as an argument other function and few other arguments. Bind arguments to nested function and return recieved function


function bindFunction(fn, ...array) {
    let args = Array.from(arguments);
    function F() {
        return args;
    }
    return F.bind(bindFunction);
}

nested function, which outer function takes as a first parameter, must to bind other parameters to nested function and return them


Solution

  • I think this is what you are looking for.

    function bindFunction(fn, ...array) {
      return fn.bind(null, ...array);
    }