Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit db6d843

Browse files
currying with bind only
1 parent 66e38e7 commit db6d843

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

‎04-functions.md‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,7 @@ hello.apply(null, ['hey!']);
182182
* use when find yourself calling a function with same arguments
183183

184184
```js
185-
// ES5 way with bind
186-
var curried = add.bind(undefined, 10);
187-
curried(5);
188-
189-
// old way
185+
// basic curry example
190186
function curriedAdd(x,y) {
191187
if(y === undefined) {
192188
return function(y) {
@@ -196,16 +192,7 @@ function curriedAdd(x,y) {
196192
return x + y;
197193
}
198194

199-
//old way with general curry function
200-
function curry(fn){
201-
var slice = Array.prototype.slice; // needed because arguments is not a real Array?
202-
var storedArgs = slice.call(arguments, 1);
203-
return function(){
204-
var newArgs = slice.call(arguments);
205-
var args = storedArgs.concat(newArgs);
206-
fn.apply(null, args);
207-
};
208-
}
209-
210-
curry(add, 10)(5);
195+
// currying with bind
196+
var curried = add.bind(undefined, 10);
197+
curried(5);
211198
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /