-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_oop_basics.js
More file actions
43 lines (34 loc) · 822 Bytes
/
10_oop_basics.js
File metadata and controls
43 lines (34 loc) · 822 Bytes
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
#!/usr/bin/env node
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
introduce() {
console.log(`Hi, I'm ${this.name} and I'm ${this.age} years old.`);
}
haveBirthday() {
this.age++;
console.log(`Happy birthday ${this.name}! Now ${this.age} years old.`);
}
}
class Employee extends Person {
constructor(name, age, job) {
super(name, age);
this.job = job;
}
introduce() {
console.log(`Hi, I'm ${this.name}, a ${this.job}, ${this.age} years old.`);
}
}
function oopBasics() {
const p = new Person("Emma", 27);
p.introduce();
p.haveBirthday();
const emp = new Employee("Bob", 35, "Software Engineer");
emp.introduce();
}
function main() {
oopBasics();
}
main();