This repository was archived by the owner on Jul 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
143 lines (115 loc) · 2.75 KB
/
example.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var Model = createClass(null, {
// constructor
init: function () {
console.log('"constructor" of Model');
},
// instance methods
data: function () {
console.log('"data" from Model instance');
},
empty: function () {
console.log('"empty" from Model instance');
}
}, {
// class methods
all: function () {
console.log('"all" from Model class');
},
at: function () {
console.log('"at" from Model class');
}
});
var Table = createClass(Model, {
// constructor
init: function () {
console.log('"constructor" of Table');
// call Model.prototype.init with context set to Table instance
this._super();
},
// instance methods
data: function () {
console.log('"data" from Table instance');
this._super();
}
}, {
// class methods
at: function () {
console.log('"at" from Table class');
// call Model.at with context set to Table
this._super();
},
findByPlayer: function () {
console.log('"findByPlayer" from Table class');
}
});
Table.extend({
data: function() {
console.log('extended "data" from Table instance');
// call oriniginal "data" method fron Table
this._super();
}
});
Table.extendClass({
at: function() {
console.log('extended "at" from Table class');
// call oriniginal method Table.at
this._super();
}
});
// you can do it again :)
Table.extend({
data: function() {
console.log('second time extended "data" from Table instance');
// call previosly extended "data" method fron Table
this._super();
}
});
Table.extendClass({
at: function() {
console.log('second time extended "at" from Table class');
// call previosly extended method Table.at
this._super();
}
});
// and again :)
Table.extend({
data: function() {
console.log('third time extended "data" from Table instance');
// call previosly extended "data" method fron Table
this._super();
}
});
Table.extendClass({
at: function() {
console.log('third time extended "at" from Table class');
// call previosly extended method Table.at
this._super();
}
});
Table.all();
// output:
// "all" from Model class
Table.at(0);
// output:
// third time extended "at" from Table class
// second time extended "at" from Table class
// extended "at" from Table class
// "at" from Table class
// "at" from Model class
Table.findByPlayer();
// output:
// "findByPlayer" from Table class
t = new Table();
// output:
// "constructor" of Table
// "constructor" of Model
t.data();
// output:
// third time extended "data" from Table instance
// second time extended "data" from Table instance
// extended "data" from Table instance
// "data" from Table instance
// "data" from Model instance
t.empty();
// output:
// "empty" from Model instance