From 86a60219fb7ff874fb29ba66d3e43840f9c7b45b Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Sun, 10 Jan 2021 15:50:14 +0300 Subject: [PATCH] minor fixes --- 1-js/99-js-misc/03-currying-partials/article.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/1-js/99-js-misc/03-currying-partials/article.md b/1-js/99-js-misc/03-currying-partials/article.md index 0c0bc28b..d71ac23f 100644 --- a/1-js/99-js-misc/03-currying-partials/article.md +++ b/1-js/99-js-misc/03-currying-partials/article.md @@ -122,7 +122,9 @@ function curry(func) { if (args.length >= func.length) { return func.apply(this, args); } else { - return curried.bind(this, ...args); + return function(...args2) { + return curried.apply(this, args.concat(args2)); + } } }; @@ -153,7 +155,9 @@ function curried(...args) { if (args.length >= func.length) { // (1) return func.apply(this, args); } else { - return curried.bind(this, ...args); // (2) + return function(...args2) { // (2) + return curried.apply(this, args.concat(args2)); + } } }; ``` @@ -161,7 +165,7 @@ function curried(...args) { When we run it, there are two `if` execution branches: 1. If passed `args` count is the same or more than the original function has in its definition (`func.length`) , then just pass the call to it using `func.apply`. -2. Otherwise, get a partial: we don't call `func` just yet. Instead, `curried.bind(this, ...args)` returns a "bound" function: the same as `curried`, but with pre-set `this` and pre-specified arguments. In other words, this is exactly where the partial variant of function is created, with first arguments fixed. +2. Otherwise, get a partial: we don't call `func` just yet. Instead, another wrapper is returned, that will re-apply `curried` providing previous arguments together with the new ones. Then, if we call it, again, we'll get either a new partial (if not enough arguments) or, finally, the result.