@@ -169,24 +169,34 @@ hello.apply(null, ['hey!']);
169
169
* ``` Function.prototype.call ``` is just syntactic sugar over apply
170
170
* call expects parameters as normal parameter list instead of an array
171
171
172
- ## partial application
172
+ ## function binding
173
+
174
+ * ``` Function.prototype.bind ``` has the same signature as ``` .call ```
175
+ * creates a new function bound to the object and optional parameters passed in
176
+
177
+ ## partial application / currying
173
178
174
179
* call a function with less than all of it's arguments
175
180
* and return a function expecting the rest of the arguments
176
181
* this transformation of function is called currying or schonfinkelizing
177
182
* use when find yourself calling a function with same arguments
178
183
179
184
``` js
185
+ // ES5 way with bind
186
+ var curried = add .bind (undefined , 10 );
187
+ curried (5 );
188
+
189
+ // old way
180
190
function curriedAdd (x ,y ) {
181
- if (y === undefined ){
182
- return function (y ){
191
+ if (y === undefined ){
192
+ return function (y ){
183
193
return x+ y;
184
194
}
185
195
}
186
196
return x + y;
187
197
}
188
198
189
- // or with more general curry function
199
+ // old way with general curry function
190
200
function curry (fn ){
191
201
var slice = Array .prototype .slice ; // needed because arguments is not a real Array?
192
202
var storedArgs = slice .call (arguments , 1 );
@@ -197,5 +207,5 @@ function curry(fn){
197
207
};
198
208
}
199
209
200
- curry (add, 6 )( 7 );
210
+ curry (add, 10 )( 5 );
201
211
```
0 commit comments