-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek4_day1 - JS - ES6 Advanced.html
139 lines (81 loc) · 2.37 KB
/
week4_day1 - JS - ES6 Advanced.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html lang="es">
<head>
<title>JS</title>
<meta charset="utf-8">
</head>
<body>
<h1>JS | ES6 Advanced</h1>
<script>
/*
// Classes and inheritance
class Person {
constructor(val1, val2, val3){
this.firstName = val1;
this.surname = val2;
this.age = val3;
}
}
class Player extends Person {
constructor(val1, val2, val3, val4){
super(val1, val2, val3)
this.points = val4
}
}
class Witch extends Player {
constructor(val1, val2, val3, val4){
super(val1, val2, val3, val4)
this.role = 'bruja'
}
lanzarHechizo(){
console.log("La bruja " + this.firstName + " te lanzó un hechizo!")
}
}
class Elf extends Player {
constructor(val1, val2, val3, val4){
super(val1, val2, val3, val4)
this.role = 'elfo'
}
escupir(){
console.log("El elfo " + this.firstName + " te escupió! Menudo guarro...")
}
}
var onlyPerson = new Person('Germán', 'Álvarez', 32)
console.log(onlyPerson.firstName + ' tiene ' + onlyPerson.age + ' años ')
var onlyPlayer = new Player('Sara', 'Díaz', 16, 2000)
console.log(onlyPlayer.firstName + ' tiene ' + onlyPlayer.points + ' puntos ')
var bruja = new Witch('Piruja', 'Ruiz', 97, 2000)
bruja.lanzarHechizo()
var elfo = new Elf('John', 'Doe', 30, 2000)
elfo.escupir()
*/
/*
// Arrow functions (example 0)
class Counter {
constructor() {
this.count = 1;
}
countUp() {
setInterval(() => {
console.log(this.count++); // <-- Great!
}, 1000);
}
}
let myCounter = new Counter();
myCounter.countUp();
// Arrow function (example 2)
const esPar = val => if (val % 2 === 0) return true
console.log(esPar(2))
// Arrow function (example 3)
const drinksHQ = ['Coca-cola', 'Sprite', 'Cacaolat', 'Rebull']
drinksHQ.forEach( drink => alert(drink) )
// Arrow function (example 3)
const numbers = [1, 2, 3, 4, 5, 6, 7, 8];
const evens = numbers.filter(singleNumber => singleNumber % 2 === 0);
console.log(evens);
// Arrow function (example 4)
window.onmousemove = e => console.log(e.x)
*/
</script>
</body>
</html>