diff --git a/snippets/bindKey.md b/snippets/bindKey.md index 147ad2ff7..3ed5d7eea 100644 --- a/snippets/bindKey.md +++ b/snippets/bindKey.md @@ -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. 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 -const bindKey = (context, fn, ...args) => - function() { - return context[fn].apply(context, args.concat(...arguments)); - }; +const bindKey = (context, fn, ...boundArgs) => (...args) => context[fn].apply(context, [...boundArgs, ...args]); ``` ```js diff --git a/test/bindKey/bindKey.js b/test/bindKey/bindKey.js index 9d43be087..9b538c735 100644 --- a/test/bindKey/bindKey.js +++ b/test/bindKey/bindKey.js @@ -1,5 +1,2 @@ -const bindKey = (context, fn, ...args) => - function() { - return context[fn].apply(context, args.concat(...arguments)); - }; +const bindKey = (context, fn, ...boundArgs) => (...args) => context[fn].apply(context, [...boundArgs, ...args]); module.exports = bindKey;