index.html
8.74 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Ext Core 4 Class Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
pre { border: 1px gray solid; padding: 5px; margin-top: 30px; }
</style>
<script type="text/javascript" src="../src/Ext.js"></script>
<script type="text/javascript" src="../src/version/Version.js"></script>
<script type="text/javascript" src="../src/lang/String.js"></script>
<script type="text/javascript" src="../src/lang/Array.js"></script>
<script type="text/javascript" src="../src/lang/Number.js"></script>
<script type="text/javascript" src="../src/lang/Date.js"></script>
<script type="text/javascript" src="../src/lang/Object.js"></script>
<script type="text/javascript" src="../src/lang/Function.js"></script>
<script type="text/javascript" src="../src/class/Base.js"></script>
<script type="text/javascript" src="../src/class/Class.js"></script>
<script type="text/javascript" src="../src/class/ClassManager.js"></script>
<script type="text/javascript" src="../src/class/Loader.js"></script>
<script type="text/javascript" src="../src/lang/Error.js"></script>
<script>
Ext.Loader.setConfig({
enabled: true,
paths: {
'Sample': 'src/Sample'
}
});
</script>
<script>
var sources = {};
function storeCode() {
var i = 0,
name,
pre;
while (++i) {
name = 'sample' + i;
pre = document.getElementById(name);
if (!pre) {
break;
}
sources[name] = pre.innerHTML;
}
}
function run(id) {
eval(sources[id]);
}
</script>
</head>
<body onload="storeCode();">
<pre id="sample1">
Ext.require('Sample.Person', function() {
var aaron = new Sample.Person({
name: 'Aaron Conran',
gender: 'male',
isCool: true
});
alert(aaron.getName()); // 'Aaron Conran'
alert(aaron.getGender()); // 'male'
alert(aaron.getIsCool()); // true
aaron.eat("Salad"); // alerts "I'm eating: Salad"
aaron.setGender('weird');
alert(aaron.getGender()); // 'unknown'
});
</pre>
<p>
<button onclick="run('sample1')">Run Code</button>
</p>
<pre id="sample2">
Ext.require('Sample.Developer', function() {
var tommy = new Sample.Developer({
name: 'Tommy Maintz',
languages: ['PHP', 'JavaScript', 'HTML', 'CSS']
});
tommy.code('Objective-C'); // alerts "I can't code in: Objective-C"
tommy.code('JavaScript'); // alerts "I'm coding in: JavaScript"
// alerts "I'm eating: Bugs"
});
</pre>
<p>
<button onclick="run('sample2')">Run Code</button>
</p>
<pre id="sample3">
Ext.require('Sample.Musician', function() {
var dave = new Sample.Musician({
name: 'David Kaneda',
isCool: true
});
dave.composeSongs(); // alerts "David Kaneda is composing songs"
dave.playGuitar(); // alerts "David Kaneda is playing guitar"
var anotherDave = Sample.Musician.clone(dave);
alert(anotherDave.getName()); // alerts "David Kaneda"
});
</pre>
<p>
<button onclick="run('sample3')">Run Code</button>
</p>
<pre id="sample4">
Ext.require('Sample.CoolGuy', function() {
var jacky = new Sample.CoolGuy({
name: 'Jacky Nguyen',
isCool: true
});
jacky.playGuitar(); // alerts "Jacky Nguyen is playing guitar"
jacky.sing("Love Me or Die"); // alerts "Ahem..."
// alerts "I'm singing: Love Me or Die"
});
</pre>
<p>
<button onclick="run('sample4')">Run Code</button>
</p>
<pre id="sample5">
Ext.require(['Sample.Developer', 'Sample.HumanResource'], function() {
var jacky = new Sample.Developer({
name: 'Jacky Nguyen',
languages: ['PHP', 'JavaScript', 'HTML', 'CSS']
}),
noobie = new Sample.Developer({
name: 'Noobie Dumb',
languages: ['LameScript']
}),
hr = Sample.HumanResource;
hr.recruit(noobie); // alerts "Noobie Dumb doesn't know JavaScript, no point recruiting!"
hr.recruit(jacky);
alert(hr.getDevelopersCount()); // alerts 1
});
</pre>
<p>
<button onclick="run('sample5')">Run Code</button>
</p>
<pre id="sample6">
Ext.require(['Sample.deadlock.A'], function() {
// should throw Error
});
</pre>
<p>
<button onclick="run('sample6')">Run Code</button>
</p>
<pre id="sample7">
Ext.require(['Sample.notdeadlock.A'], function() {
alert("Loading sequence: " + Ext.Loader.history.join(" -> "));
});
</pre>
<p>
<button onclick="run('sample7')">Run Code</button>
</p>
<pre id="sample8">
Ext.require(['Sample.CTO', 'Sample.Developer'], function() {
var abe = new Sample.CTO();
alert(abe.isGeek); // alerts true
alert(abe.isSuperGeek); // alerts true
alert(abe.getAverageIQ()); // alerts 140
// not the current class
var ape = abe.clone();
alert(Ext.getClassName(ape)); // alerts 'Sample.CTO'
var jacky = new Sample.Developer();
alert(jacky.getAverageIQ()); // alerts 120
var jackie = abe.hireNewDeveloperLike(jacky);
alert(Ext.getClassName(jackie)); // alerts 'Sample.Developer'
});
</pre>
<p>
<button onclick="run('sample8')">Run Code</button>
</p>
<pre id="sample9">
Ext.define('My.own.A', {
statics: {
myName: 'A'
},
constructor: function() {
alert(this.statics().myName);
alert(this.self.myName);
},
clone: function() {
var cloned = new this.self();
cloned.rootName = this.statics().myName;
return cloned;
}
});
Ext.define('My.own.B', {
extend: 'My.own.A',
statics: {
myName: 'B'
},
clone: function() {
var cloned = this.callParent();
cloned.special = true;
return cloned;
}
});
var a = new My.own.A(); // alerts 'A' then alerts 'A'
var b = new My.own.B(); // alerts 'A' then alerts 'B'
var aa = a.clone();
var bb = b.clone();
alert(Ext.getClassName(aa)); // alerts 'My.own.A'
alert(Ext.getClassName(bb)); // alerts 'My.own.B'
alert(aa.rootName); // alerts 'A'
alert(bb.rootName); // alerts 'A'
alert(bb.special); // alerts true
</pre>
<p>
<button onclick="run('sample9')">Run Code</button>
</p>
<pre id="sample10">
Ext.define('My.Cat', {
statics: {
totalCreated: 0,
speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
},
constructor: function() {
var statics = this.statics();
alert(statics.speciesName); // always equals to 'Cat' no matter what 'this' refers to
// equivalent to: My.Cat.speciesName
alert(this.self.speciesName); // dependent on 'this'
statics.totalCreated++;
return this;
},
clone: function() {
var cloned = new this.self; // dependent on 'this'
cloned.groupName = this.statics().speciesName; // equivalent to: My.Cat.speciesName
return cloned;
}
});
Ext.define('My.SnowLeopard', {
extend: 'My.Cat',
statics: {
speciesName: 'Snow Leopard' // My.SnowLeopard.speciesName = 'Snow Leopard'
},
constructor: function() {
this.callParent();
}
});
var cat = new My.Cat(); // alerts 'Cat', then alerts 'Cat'
var snowLeopard = new My.SnowLeopard(); // alerts 'Cat', then alerts 'Snow Leopard'
var clone = snowLeopard.clone();
alert(Ext.getClassName(clone)); // alerts 'My.SnowLeopard'
alert(clone.groupName); // alerts 'Cat'
alert(My.Cat.totalCreated); // alerts 3
</pre>
<p>
<button onclick="run('sample10')">Run Code</button>
</p>
<pre id="sample11">
Ext.define('Bank', {
money: '$$$',
printMoney: function() {
alert('$$$$$$$');
}
});
Ext.define('Thief', {});
Thief.borrow(Bank, ['money', 'printMoney']);
var jacky = new Thief();
alert(jacky.money); // alerts '$$$'
jacky.printMoney(); // alerts '$$$$$$$'
</pre>
<p>
<button onclick="run('sample11')">Run Code</button>
</p>
</body>
</html>