forked from vladilenm/SOLID_javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_L.js
80 lines (67 loc) · 1.43 KB
/
3_L.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
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
80
// Liskov substitution principle
// class Person {
//
// }
//
// class Member extends Person {
// access() {
// console.log('У тебя есть доступ')
// }
// }
//
// class Guest extends Person {
// isGuest = true
// }
//
// class Frontend extends Member {
// canCreateFrontend() {}
// }
//
// class Backend extends Member {
// canCreateBackend() {}
// }
//
// class PersonFromDifferentCompany extends Guest {
// access() {
// throw new Error('У тебя нет доступа! Иди к себе!')
// }
// }
//
// function openSecretDoor(member) {
// member.access()
// }
//
// openSecretDoor(new Frontend())
// openSecretDoor(new Backend())
// openSecretDoor(new PersonFromDifferentCompany()) // There should be member!
// ===============
class Component {
isComponent = true
}
class ComponentWithTemplate extends Component {
render() {
return `<div>Component</div>`
}
}
class HigherOrderComponent extends Component {
}
class HeaderComponent extends ComponentWithTemplate {
onInit() {}
}
class FooterComponent extends ComponentWithTemplate {
afterInit() {}
}
class HOC extends HigherOrderComponent {
render() {
throw new Error('Render is impossible here')
}
wrapComponent(component) {
component.wrapped = true
return component
}
}
function renderComponent(component) {
console.log(component.render())
}
renderComponent(new HeaderComponent())
renderComponent(new FooterComponent())