1 Ext.define('Computer',{
2 statics:{
3 instanceCount:0,
4 factory:function(brand){
5 // 'this' in static methods refer to the class itself
6 return new this({brand: brand}); }
7 },
8 config:{ brand:null },
9 constructor:function(config){
10 this.initConfig(config);
11 // the 'self' property of an instance refers to its class
12 this.self.instanceCount++;
13 return this;
14 }
15 });
1 var dellComputer=Computer.factory('Dell');
2 var appleComputer=Computer.factory('Mac');
3 alert(appleComputer.getBrand());// using the auto-generated getter to get the value of a config property. Alerts "Mac"
4 alert(Computer.instanceCount);// Alerts "2"