-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-class.js
More file actions
62 lines (47 loc) · 1.28 KB
/
example-class.js
File metadata and controls
62 lines (47 loc) · 1.28 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
class MyClassParent {
constructor(name, lastname, age) {
this.name = name
this.lastname = lastname
this.age = age
}
getName() {
return this.name;
}
getLastName() {
return this.lastname;
}
getAge() {
return this.age;
}
setAge(newAge) {
this.age = newAge
}
}
const myParentObject = new MyClassParent('Franco', 'Lavayen', 29);
myParentObject.setAge(30);
console.log('My age is: ' + myParentObject.getAge());
console.log('#################################');
/* Herencia con clases */
class MyClassChild extends MyClassParent {
constructor(name, lastname, age, color, sport) {
super(name, lastname, age)
this.favoriteColor = color;
this.sport = sport;
}
getFavortiteColor() {
return this.favoriteColor;
}
getSport() {
return this.sport;
}
setChangeSport(newSport) {
this.sport = newSport
}
}
// Create new child object that extends from parent class
const childObject = new MyClassChild('Juan', 'Perez', 25, 'Green', 'Tenis');
console.log(childObject);
// Set new age to child object using the parent method
childObject.setAge(50);
// Print the child object properties with the new changes
console.log(childObject);