@@ -167,4 +167,35 @@ hello.apply(null, ['hey!']);
167
167
* second argument is an array of arguments
168
168
* in non-strict mode if first argument is null then it'll point at the global object
169
169
* ``` Function.prototype.call ``` is just syntactic sugar over apply
170
- * call expects parameters as normal instead of an array
170
+ * call expects parameters as normal parameter list instead of an array
171
+
172
+ ## partial application
173
+
174
+ * call a function with less than all of it's arguments
175
+ * and return a function expecting the rest of the arguments
176
+ * this transformation of function is called currying or schonfinkelizing
177
+ * use when find yourself calling a function with same arguments
178
+
179
+ ``` js
180
+ function curriedAdd (x ,y ) {
181
+ if (y === undefined ){
182
+ return function (y ){
183
+ return x+ y;
184
+ }
185
+ }
186
+ return x + y;
187
+ }
188
+
189
+ // or with more general curry function
190
+ function curry (fn ){
191
+ var slice = Array .prototype .slice ; // needed because arguments is not a real Array?
192
+ var storedArgs = slice .call (arguments , 1 );
193
+ return function (){
194
+ var newArgs = slice .call (arguments );
195
+ var args = storedArgs .concat (newArgs);
196
+ fn .apply (null , args);
197
+ };
198
+ }
199
+
200
+ curry (add, 6 )(7 );
201
+ ```
0 commit comments