Skip to content

Commit 86a6021

Browse files
committed
minor fixes
1 parent 2027939 commit 86a6021

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

1-js/99-js-misc/03-currying-partials/article.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ function curry(func) {
122122
if (args.length >= func.length) {
123123
return func.apply(this, args);
124124
} else {
125-
return curried.bind(this, ...args);
125+
return function(...args2) {
126+
return curried.apply(this, args.concat(args2));
127+
}
126128
}
127129
};
128130

@@ -153,15 +155,17 @@ function curried(...args) {
153155
if (args.length >= func.length) { // (1)
154156
return func.apply(this, args);
155157
} else {
156-
return curried.bind(this, ...args); // (2)
158+
return function(...args2) { // (2)
159+
return curried.apply(this, args.concat(args2));
160+
}
157161
}
158162
};
159163
```
160164

161165
When we run it, there are two `if` execution branches:
162166

163167
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`.
164-
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.
168+
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.
165169

166170
Then, if we call it, again, we'll get either a new partial (if not enough arguments) or, finally, the result.
167171

0 commit comments

Comments
 (0)