Files
30-seconds-of-code/snippets/js/s/prepend-function-arguments.md
Angelos Chalaris 9d032ce05e Rename js snippets
2023-05-19 20:23:47 +03:00

579 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Prepend function arguments snippet javascript
function
interior-6 2020-09-15T16:28:04+03:00

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

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