Get rid of arguments for bindKey
This commit is contained in:
@ -3,13 +3,10 @@
|
|||||||
Creates a function that invokes the method at a given key of an object, optionally adding any additional supplied parameters to the beginning of the arguments.
|
Creates a function that invokes the method at a given key of an object, optionally adding any additional supplied parameters to the beginning of the arguments.
|
||||||
|
|
||||||
Return a `function` that uses `Function.apply()` to bind `context[fn]` to `context`.
|
Return a `function` that uses `Function.apply()` to bind `context[fn]` to `context`.
|
||||||
Use `Array.concat()` to prepend any additional supplied parameters to the arguments.
|
Use spread operator to prepend any additional supplied parameters to the arguments.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const bindKey = (context, fn, ...args) =>
|
const bindKey = (context, fn, ...boundArgs) => (...args) => context[fn].apply(context, [...boundArgs, ...args]);
|
||||||
function() {
|
|
||||||
return context[fn].apply(context, args.concat(...arguments));
|
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
@ -1,5 +1,2 @@
|
|||||||
const bindKey = (context, fn, ...args) =>
|
const bindKey = (context, fn, ...boundArgs) => (...args) => context[fn].apply(context, [...boundArgs, ...args]);
|
||||||
function() {
|
|
||||||
return context[fn].apply(context, args.concat(...arguments));
|
|
||||||
};
|
|
||||||
module.exports = bindKey;
|
module.exports = bindKey;
|
||||||
|
|||||||
Reference in New Issue
Block a user