2020-03-11
描述
创建一个函数,当调用 fn 时,将 partials 添加到最终执行函数所接受的参数之后。
提示
- 使用扩展运算符
...将partials添加到fn的参数列表之后
代码
const partialRight = (fn, ...partials) => (...args) => fn(...args, ...partials);
示例
对同一个朋友进行不同的问候:
const greet = (greeting, name) => greeting + ' ' + name + '!';
const greetJohn = partialRight(greet, 'John');
greetJohn('Hello'); // 'Hello John!'
greetJohn('How are you?'); // 'How are you? John!'
ME!
链滴