-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_class_inheritance_2.js
116 lines (93 loc) · 1.71 KB
/
js_class_inheritance_2.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
class Parent {
x = 10;
y = 20;
z = 30;
total() {
const sum = this.x + this.y + this.z;
console.log(`PARENT : ${sum}`);
}
adele() {
console.log('hello-from-the-other-side');
}
}
class Child extends Parent {
x = 11;
y = 21;
z = 31;
total() {
const sum = this.x + this.y + this.z;
console.log(`CHILD : ${sum}`);
}
comparison() {
super.total();
this.total();
Parent.prototype.total.call(this);
}
}
const parent = new Parent();
const child = new Child();
function F01() {
parent.total();
parent.total.call(parent);
parent.total.call(child);
}
function F02() {
Parent.prototype.total();
Parent.prototype.total.call(parent);
Parent.prototype.total.call(child);
}
function F03() {
child.total();
child.total.call(parent);
child.total.call(child);
}
function F04() {
Child.prototype.total();
Child.prototype.total.call(parent);
Child.prototype.total.call(child);
}
function F05() {
child.comparison();
Child.prototype.comparison.call(child);
}
function F06() {
parent.adele();
Parent.prototype.adele();
child.adele();
Child.prototype.adele();
}
function F07() {
console.log(parent.x);
console.log(Parent.prototype.x);
parent.x = 40;
Parent.prototype.x = 50;
const foster = new Parent();
parent.total();
foster.total();
}
function F08() {
console.log(parent.total);
console.log(Parent.prototype.total);
parent.total = function () {
console.log(this.x);
};
Parent.prototype.total = function () {
console.log(this.x ** 2);
};
const foster = new Parent();
parent.total();
foster.total();
}
function F09() {
console.log(parent.constructor.__proto__.name);
console.log(child.constructor.__proto__.name);
}
F01();
F02();
F03();
F04();
F05();
F06();
F07();
F08();
F09();