-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.js
More file actions
33 lines (29 loc) · 935 Bytes
/
inheritance.js
File metadata and controls
33 lines (29 loc) · 935 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
class Person {
constructor(firstName, lastName){
this.first = firstName
this.last = lastName
}
logPerson(){
console.log(`${this.first} ${this.last}`)
}
}
class Employee extends Person{
constructor(firstName, lastName, jobTitle, salary){
super(firstName, lastName)
this.jobTitle = jobTitle
this.salary = salary
}
logJobDetails(){
console.log(`${this.first} ${this.last} is currently working as a ${this.jobTitle} and earning: $${this.salary}`)
}
}
const chase = new Person("Chase", "Lones")
console.log(chase.first) // Chase
console.log(chase.last) // lones
chase.logPerson() // Chase Lones
const gulnar = new Employee('Gulnar', 'Hasan-zada', 'Principal Fullstack Develoer', 350000)
console.log(gulnar.first)
console.log(gulnar.last)
console.log(gulnar.jobTitle)
console.log(gulnar.salary)
gulnar.logJobDetails()