-
Notifications
You must be signed in to change notification settings - Fork 0
/
currying.html
94 lines (67 loc) · 1.92 KB
/
currying.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
1. Bind - function curring usign bind method create a multiple methiods.
<br>
<br>
2. Closer - You can use preset values x in inner second function
<br>
<br>
https://www.youtube.com/watch?v=75W8UPQ5l7k
3. Call, Apply and Bind functions
Call :- function borrowing
<script type="text/javascript">
// 1. Bind - function curring usign bind method create a multiple methiods.
// 2. Closer
let multiply = function (x,y){
console.log(x*y);
}
//This function same like bealow single line function
/*let multiplyByTwo = function(Y){
let x = 2;
console.log(x*y);
}
let multiplyByTwo = multiply.bind(this,2);
*/
/*
in argument last values is for Y
let multiplyByTwo = multiply.bind(this,2,3);
or
multiplyByTwo(2,3);
*/
let multiplyByTwo = multiply.bind(this,2);
multiplyByTwo(3);
let multiplyByThree = multiply.bind(this,3);
multiplyByThree(5);
/*
Closer
You can use preset values x in second function
*/
let multiply1 = function (x){
return function(y){
console.log(x*y);
}
}
// Remove a bind function and pass direct argument
let multiplyByTwo1 = multiply1(2);
multiplyByTwo1(3);
//Call fucntion : - invoke a fucntion passing directily argument by comma sperated
let name = {
firstname : "ravi",
lastname : "kumar",
printFullName : function(hometown, state){
console.log(this.firstname + " " +this.lastname + " from " + hometown + " " + state);
}
}
name.printFullName("Ahmedabad","Guj");
let name2 = {
firstname : "Rv",
lastname : "Patel",
}
//fucntion borrowing
name.printFullName.call(name2,"Mumbai","Mah");
//Apply method => pass value as a array list []
name.printFullName.apply(name2,["A","B"]);
//Bind methord : does not invoke direct but fucntion retun inoke later
let printmyname = name.printFullName.bind(name2,"Mumbai","Mah");
//return a full fucntion
console.log(printmyname);
printmyname();
</script>