-
Notifications
You must be signed in to change notification settings - Fork 0
/
17_CloserLookAtFunctions.js
41 lines (29 loc) · 974 Bytes
/
17_CloserLookAtFunctions.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
/*--------------------------------------------------------------*/
/* Defualt values for parameters
----------------------------------------------------------------*/
class Person {
constructor(firstname, lastname, age){
this.firstname = firstname
this.lastname = lastname
this.age = age
}
}
const dima = new Person("Dima", "Anikin", 21)
function getFullname(person, prefix = "Mr.") {
return `Fullname: ${prefix} ${person.firstname} ${person.lastname}`
}
const dimaFull = getFullname(dima)
// console.log(dimaFull);
/*--------------------------------------------------------------*/
/* Closures (calling two functions at a time)
----------------------------------------------------------------*/
function greet(greeting) {
return function(name) {
console.log(`${greeting} ${name}!`);
}
}
const helloing = greet('Hello')
const heying = greet("Hey")
// helloing("Dima")
// heying("Dima")
// greet("Sup")("Dima")