-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample2.js
68 lines (44 loc) · 1.07 KB
/
sample2.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
/*
Sample 2 (new way)
*/
var Parent = (function(){
function Parent(msg){
this.log(msg);
}
Parent.prototype.log = function(msg){
if(window.console) console.log(msg);
}
Parent.prototype.val = 10;
Parent.prototype.getVal = function(){
return this.val;
}
return Parent;
})();
var Child = (function(_super){
function Child(msg){
this.log(msg);
}
Child.prototype = new _super;
Child.prototype.val = 100;
Child.prototype.getVal = function(){
return _super.prototype.getVal.call(this) + "!";
}
return Child;
})(Parent);
var GrandChild = (function(_super){
function GrandChild(msg){
this.log(msg);
}
GrandChild.prototype = new _super;
GrandChild.prototype.val = 100000;
GrandChild.prototype.getVal = function(){
return _super.prototype.getVal.call(this) + "!!";
}
return GrandChild;
})(Child);
var parent = new Parent("new Parent constuctor");
var child = new Child("new Child constuctor");
var grandChild = new GrandChild("new GrandChild constuctor");
parent.log(parent.getVal());
child.log(child.getVal());
grandChild.log(grandChild.getVal());