From c3015e47fce75d9068dd7b5099bf423470a86b06 Mon Sep 17 00:00:00 2001 From: Siarhei Date: Fri, 10 Aug 2018 11:40:33 +0400 Subject: [PATCH] Get rid of arguments for bindKey --- snippets/bindKey.md | 7 ++----- test/bindKey/bindKey.js | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) 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;