You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: legacy-patterns.md
+12-8
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,10 @@
1
-
# 6. Code re-use patterns
1
+
# Legacy patterns
2
2
3
-
## classical inheritance
3
+
Event though the book is amazing some patterns so the signs of aging (e.g. replaced by ES5 feautures or turned out to be bad ideas) Moved some of the older patterns here.
4
+
5
+
## 6. Code re-use patterns
6
+
7
+
### classical inheritance
4
8
5
9
* play on the word 'class', nothing to do with the word classical
6
10
* JavaScript has no classes but constructor functions make same people think that
@@ -16,7 +20,7 @@ inherit(Child, Parent);
16
20
17
21
* inherit is not part of the language have to implement it yourself
18
22
19
-
## classical default pattern
23
+
###classical default pattern
20
24
21
25
```js
22
26
functioninherit(Child, Parent){
@@ -28,7 +32,7 @@ function inherit(Child, Parent){
28
32
* drawback: children gets both own and prototype properties from parent
29
33
* drawback: can't really pass parameters, or end up with a lot of objects
30
34
31
-
## classical rent-a-constructor pattern
35
+
###classical rent-a-constructor pattern
32
36
33
37
```js
34
38
functionChild(a, b, c, d){
@@ -47,7 +51,7 @@ function Child(a, b, c, d){
47
51
* multiple inheritance can be achieved by applying more than one constructors
48
52
* in case of multiple inheritance and duplicate properties - last one wins
49
53
50
-
## classical rent-and-set prototype
54
+
###classical rent-and-set prototype
51
55
52
56
```js
53
57
functionChild(a, b, c, d){
@@ -60,7 +64,7 @@ Child.prototype = new Parent();
60
64
* and references re-usable functionality (from parents prototype)
61
65
* drawback: parent constructor is called twice
62
66
63
-
## classical share the prototype pattern
67
+
###classical share the prototype pattern
64
68
65
69
```js
66
70
functioninherit(Child, Parent){
@@ -72,7 +76,7 @@ function inherit(Child, Parent){
72
76
* fast lookups as all object references one prototype
73
77
* BUT children can modify parent behaviour
74
78
75
-
## classical temporary constructor pattern
79
+
###classical temporary constructor pattern
76
80
77
81
```js
78
82
functioninherit(Child,Parent){
@@ -102,7 +106,7 @@ var inherit = (function(){
102
106
})();
103
107
```
104
108
105
-
## klass
109
+
###klass
106
110
107
111
* some legacy JS libraries/frameworks emulate classes
108
112
* usually there's a convention on how to name constructor functions (e.g. init)
0 commit comments