-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverridingConstructor.js
40 lines (36 loc) · 1.05 KB
/
OverridingConstructor.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
class Employee {
constructor(name) {
console.log(`${name} - Employee's constructor is here`);
this.name = name;
}
login() {
console.log(`Employee has logged in`);
}
logout() {
console.log(`Employee has logged out`);
}
requestLeaves(leaves) {
console.log(`Employee has requested ${leaves} leaves - Auto approved`);
}
}
class Programmer extends Employee {
constructor(name) {
// this.name; // it will give error, as this must be written after super constructor.
super(name); // must utilize this constructor
console.log(`This is a newly written constructor.`);
}
// constructor(...args){ ---> If there is no constructor in the child class, this is created automatically
// super(...args)
// }
requestCoffee(x) {
console.log(`Employee has requested ${x} coffees`);
}
requestLeaves(leaves) {
super.requestLeaves(4);
console.log("One extra is granted");
// console.log(`Employee has requested ${leaves + 1} leaves (One extra)`)
}
}
let e = new Programmer("Harry");
e.login();
e.requestLeaves(3);