Append function arguments

OSCC · JavaScript, Function · Sep 15, 2020

Creates a function that invokes fn with partials appended to the arguments it receives.

  • Use the spread operator (...) to append partials to the list of arguments of fn.
const partialRight = (fn, ...partials) => (...args) => fn(...args, ...partials);
const greet = (greeting, name) => greeting + ' ' + name + '!';
const greetJohn = partialRight(greet, 'John');
greetJohn('Hello'); // 'Hello John!'

Recommended snippets

  • Prepend function arguments

    JavaScript, Function

    Creates a function that invokes fn with partials prepended to the arguments it receives.

  • Bind function context

    JavaScript, Function

    Creates a function that invokes fn with a given context, optionally prepending any additional supplied parameters to the arguments.

  • Invoke functions on arguments

    JavaScript, Function

    Creates a function that invokes each provided function with the arguments it receives and returns the results.