-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass1.js
More file actions
79 lines (59 loc) · 1.51 KB
/
class1.js
File metadata and controls
79 lines (59 loc) · 1.51 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class User {
isPermenantEmployee = false;
constructor(firstName, lastName) {
this.firstName = firstName
this.lastName = lastName
}
set firstName(a) {
this._firstName = User.changeNameCase(a);
}
get firstName() {
return this._firstName;
}
set lastName(b) {
this._lastName = User.changeNameCase(b);
}
get lastName() {
return this._lastName;
}
static changeNameCase = (value) => {
if(!value) return ''
return `${value[0].toUpperCase()}${value.slice(1)}`
}
#fullName() {
return `${this.firstName} ${this.lastName}`
}
getUserInfo() {
return {
firstName: this.firstName,
lastName: this.lastName,
fullName: this.#fullName(),
isPermenantEmployee: this.isPermenantEmployee
}
}
changeName = (firstName, lastName) => {
this.firstName = firstName;
this.lastName = lastName;
}
}
// adding User structure in Super User
class SuperUser extends User {
constructor() {
super("mighty", "god")
}
hireEmployee() {
console.log("employee hired");
}
getUserInfo() {
const data = super.getUserInfo()
console.log(data);
return {...data, isPermenantEmployee: true }
}
}
class Admin extends User {
}
const u = new User("yagnesh", "modh");
console.log(u.getUserInfo());
const sa = new SuperUser();
console.log(sa.getUserInfo());
console.log(sa.hireEmployee());