-
Notifications
You must be signed in to change notification settings - Fork 0
/
clases.js
230 lines (217 loc) · 4.8 KB
/
clases.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
class Comment{
constructor({
content,
studentName,
studentRole = "estudiante"
}){
this.content = content;
this.studentName = studentName;
this.studentRole = studentRole;
this.likes = 0;
}
publicar() {
console.log(this.studentName + " (" + this.studentRole + ")");
console.log(this.likes + " likes");
console.log(this.content);
}
}
//objetos literales
const amor ={
name: "bri",
edad: 21,
caracteristicas:[
"Hermosa",
"Encantadora"
],
masCaractericticas(nueva){
this.caracteristicas.push(nueva);
},
};
//prototipos (clases) con instancia
function Student1(name, age, cursosAprobados) {
this.name = name;
this.age = age;
this.cursosAprobados = cursosAprobados;
}
Student1.prototype.aprobarCurso = function (nuevoCursito) {
this.cursosAprobados.push(nuevoCursito);
}
const brissa = new Student1(
"Brissa Jhulianne",
21,
[
"Curso de Enamoramiento",
"Curso de Creación de amor",
],
);
class Course {
constructor({
name,
classes = [],
isFree = false,
lang = "spanish",
}) {
this._name = name;
this.classes = classes;
this.isFree = isFree;
this.lang = lang;
}
get name() {
return this._name;
}
set name(nuevoNombrecito) {
if (nuevoNombrecito === "Curso Malito de Programación Básica") {
console.error("Web... no");
} else {
this._name = nuevoNombrecito;
}
}
}
const cursoProgBasica = new Course({
name: "Curso Gratis de Programación Básica",
isFree: true,
});
const cursoDefinitivoHTML = new Course({
name: "Curso Definitivo de HTML y CSS",
});
const cursoPracticoHTML = new Course({
name: "Curso Practico de HTML y CSS",
lang: "english",
});
class LearningPath {
constructor({
name,
courses = [],
}) {
this.name = name;
this.courses = courses;
}
}
const escuelaWeb = new LearningPath({
name: "Escuela de Desarrollo Web",
courses: [
cursoProgBasica,
cursoDefinitivoHTML,
cursoPracticoHTML,
],
});
const escuelaData = new LearningPath({
name: "Escuela de Data Science",
courses: [
cursoProgBasica,
"Curso DataBusiness",
"Curso Dataviz",
],
});
const escuelaVgs = new LearningPath({
name: "Escuela de Vidweojuegos",
courses: [
cursoProgBasica,
"Curso de Unity",
"Curso de Unreal",
],
})
class Student {
constructor({
name,
email,
username,
twitter = undefined,
instagram = undefined,
facebook = undefined,
approvedCourses = [],
learningPaths = [],
}) {
this.name = name;
this.email = email;
this.username = username;
this.socialMedia = {
twitter,
instagram,
facebook,
};
this.approvedCourses = approvedCourses;
this.learningPaths = learningPaths;
}
publicarComentario(commentContent) {
const comment = new Comment({
content: commentContent,
studentName: this.name,
});
comment.publicar();
}
}
class FreeStudent extends Student {
constructor(props) {
super(props);
}
approveCourse(newCourse) {
if (newCourse.isFree) {
this.approvedCourses.push(newCourse);
} else {
console.warn("Lo sentimos, " + this.name + ", solo puedes tomar cursos abiertos");
}
}
}
class BasicStudent extends Student {
constructor(props) {
super(props);
}
approveCourse(newCourse) {
if (newCourse.lang !== "english") {
this.approvedCourses.push(newCourse);
} else {
console.warn("Lo sentimos, " + this.name + ", no puedes tomar cursos en inglés");
}
}
}
class ExpertStudent extends Student {
constructor(props) {
super(props);
}
approveCourse(newCourse) {
this.approvedCourses.push(newCourse);
}
}
class TeacherStudent extends Student {
constructor(props) {
super(props);
}
approveCourse(newCourse) {
this.approvedCourses.push(newCourse);
}
publicarComentario(commentContent) {
const comment = new Comment({
content: commentContent,
studentName: this.name,
studentRole: "profesor",
});
comment.publicar();
}
}
const juan = new FreeStudent({
name: "JuanDC",
username: "juandc",
email: "juanito@juanito.com",
twitter: "fjuandc",
learningPaths: [
escuelaWeb,
escuelaVgs,
],
});
const miguelito = new BasicStudent({
name: "Miguelito",
username: "migelitofeliz",
email: "miguelito@juanito.com",
instagram: "migelito_feliz",
learningPaths: [
escuelaWeb,
escuelaData,
],
});
const freddy = new TeacherStudent({
name: "Freddy Vega",
username: "freddier",
email: "f@gep.com",
instagram: "freddiervega",
});