Skip to content

Commit 3ffddfc

Browse files
authored
Merge pull request mouredev#4576 from bernatcs/main
#26 - javascript
2 parents 255e9ee + 7dad84b commit 3ffddfc

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// ** EJERCICIO
2+
3+
// correcta
4+
5+
const basededatos = ['Pepe', 'Pepa']
6+
7+
class User {
8+
constructor(name, email) {
9+
this.name = name;
10+
this.email = email;
11+
}
12+
13+
getUserData() {
14+
return `Name: ${this.name}, Email: ${this.email}`;
15+
}
16+
}
17+
18+
class UserRepository {
19+
save(user) {
20+
basededatos.push(user.name)
21+
}
22+
}
23+
24+
const user = new User('Bernat', '[email protected]');
25+
console.log(user.getUserData());
26+
27+
const userRepository = new UserRepository();
28+
userRepository.save(user);
29+
console.log(basededatos)
30+
31+
// incorrecta
32+
33+
class User2 {
34+
constructor(name, email) {
35+
this.name = name;
36+
this.email = email;
37+
}
38+
39+
getUserData() {
40+
return `Name: ${this.name}, Email: ${this.email}`;
41+
}
42+
43+
saveToDatabase() {
44+
basededatos.push(user2.name)
45+
}
46+
}
47+
48+
// Uso
49+
const user2 = new User2('Bernat', '[email protected]');
50+
console.log(user2.getUserData());
51+
user2.saveToDatabase();

0 commit comments

Comments
 (0)