-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionCurrying.js
More file actions
25 lines (20 loc) · 840 Bytes
/
FunctionCurrying.js
File metadata and controls
25 lines (20 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//function currying nothing but sharing a function for multiple use cases by using concept of binding and clousure
function multiply(x,y){
let z=x*y;
console.log(x,y);
console.log(z);
}
const multiplyTwo=multiply.bind(this);//here wht i have observed is while binding by ,emtioning this keyword in firt param is refereining that function
multiplyTwo(3,5);
const multiplyThree=multiply.bind(this,2);//here wht i have observed is while binding by ,emtioning this keyword in firt param is refereining that function
multiplyThree(3,6);
// lets see by using closure
const multiple=function(x){//here this second function forms a clousre with its parent lexical enviroment
return function(y){
console.log(x*y);
}
}
// console.log(multiple()(3));
const multiplyTwos=multiple(2);
multiplyTwos(3);
// multiple(3)(6);