-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
54 lines (41 loc) · 1.24 KB
/
index.js
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
(function(context) {
function multiply(a, b) {
return a * b;
}
function greet(language, person) {
const greet = language === 'es' ? 'Hola' : 'Hello';
console.log(`${greet} ${person.fname} ${person.lname}`);
}
function goodbye(language) {
return function(person) {
const goodbye = language === 'ru' ? 'Dasvidaniya' : 'Good bye';
console.log(`${goodbye} ${person.fname} ${person.lname}`);
}
}
function demo() {
const johnSnow = {
fname: 'John',
lname: 'Snow'
};
// curried function call
goodbye('ru')(johnSnow);
// or
const goodbyeInEnglish = goodbye('en');
const goodbyeInRussian = goodbye('ru');
goodbyeInEnglish(johnSnow);
goodbyeInRussian(johnSnow);
// regular function call
greet('es', johnSnow);
// curried using bind
const greetInEnglish = greet.bind(this, 'en');
const greetInSpanish = greet.bind(this, 'es');
greetInEnglish(johnSnow);
greetInSpanish(johnSnow);
// also few other functions curried with bind
const twice = multiply.bind(this, 2);
const thrice = multiply.bind(this, 3);
console.log(twice(5));
console.log(thrice(10));
}
(context || this).demoLibs['func-curry'] = demo;
})(window);