/
Examples_Inheritance_2.ts
47 lines (42 loc) · 1.18 KB
/
Examples_Inheritance_2.ts
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
class UserOne {
email: string = "";
createDate: number = 0;
lastLogin: number = 0;
token: string = ""
setToken(token: string): void {
// set user token
this.token = token;
}
resetPassword(password: string):string {
// return string of new password
return password;
}
}
class AdminUser extends UserOne {
// pages admin has access to
adminPages: string [] = ["admin", "settings"];
// method that allows the admin to reset other users
resetUserPassword(email: string):string {
// return default user password
return "password123";
}
}
class SuperAdmin extends AdminUser {
superPages: string[] = ["super", "ultimate"]
readonly myHash: string
constructor() {
super()
this.myHash = '1234567'
}
createAdminUser(adminUser: AdminUser ): AdminUser {
return adminUser
}
resetPassword(password: string): string {
// add hash to password
return password + this.myHash;
}
}
const superAdmin = new SuperAdmin()
const newAdmin = new AdminUser()
console.log( superAdmin.resetPassword('iampassword'))
console.log( newAdmin.resetPassword('iampassword'))