-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_first-class.js
More file actions
103 lines (73 loc) · 1.54 KB
/
3_first-class.js
File metadata and controls
103 lines (73 loc) · 1.54 KB
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
95
96
97
98
99
100
101
102
103
// @TODO refactor so function/arrow is used properly
//Function used as argument
function nameRetF(s) {
return s;
}
function fullnameF(name, surname) {
console.log(name + " " + surname);
}
fullnameF(nameRetF("Branislav"), "Simsic");
//Arrow used as argument
const nameRetA = (n) => n;
const fullnameA = () => console.log(nameRetA('Jovan'), 'Zvizdic');
fullnameA();
//Function returns function
function n() {
console.log('Obrad');
}
function retFunction() {
return n();
}
retFunction();
//Arrow returns arrow
const fAsValue = () => console.log('Petar');
const fAs = () => fAsValue();
fAs();
//Function used as value
function fValue(number) {
return number*3;
}
const numValueF = fValue(3);
console.log(numValueF);
//Function
const peopleA = {
names: ['Stefan', 'Njegos', 'Risto', 'Vuk'],
funcNames:function() {
console.log(this.names)
}
};
peopleA.funcNames();
//Arrow and function
function name() {
this.array = [1, 2, 3];
const self = this;
function subFunction() {
console.log(this.array); // supposed to be undefined
console.log(self.array); // 1, 2, 3
}
subFunction();
func = () => {
console.log(self.array); // 1, 2, 3
console.log(this.array); // 1, 2, 3
};
func()
}
name();
//Function
const cat1 = {
lives: 9,
jumps: function (){
this.lives--;
}
}
cat1.jumps();
console.log(cat1.lives);
//Arrow
const cat2 = {
lives: 9,
jumps: () => {
this.lives--;
}
}
cat2.jumps();
console.log(cat2.lives);