MyCompany.useful_util.Debug_Toolbar 不鼓励这样命名 MyCompany.util.Base64 可接受的命名
MyCompany.data.CoolProxy MyCompany.Application
Ext.data.JsonProxy instead of Ext.data.JSONProxy MyCompany.util.HtmlParser instead of MyCompary.parser.HTMLParser MyCompany.server.Http instead of MyCompany.server.HTTP
Ext.util.Observable is stored in path/to/src/Ext/util/Observable.js Ext.form.action.Submit is stored in path/to/src/Ext/form/action/Submit.js MyCompany.chart.axis.Numeric is stored in path/to/src/MyCompany/chart/axis/Numeric.js
Ext.MessageBox.YES = "Yes" Ext.MessageBox.NO = "No" MyCompany.alien.Math.PI = "4.13"
var MyWindow = Ext.extend(Object, { ... });
Ext.define('My.sample.Person', { name: 'Unknown', constructor: function(name) { if (name) { this.name = name; } }, eat: function(foodType) { alert(this.name + " is eating: " + foodType); } }); var aaron = Ext.create('My.sample.Person', 'Aaron'); aaron.eat("Salad"); // alert("Aaron is eating: Salad");
上面用Ext.cteate()方法创建了类My.sample.Person的实例。可以使用new关键字(new My.sample.Person())。但是习惯是总是使用Ext.create因为它在动态加载上有优势。有关动态加载在Extjs-start中有提到。
Ext.define('My.own.Window', { /** @readonly */ isWindow: true, config: { title: 'Title Here', bottomBar: { enabled: true, height: 50, resizable: false } }, constructor: function(config) { this.initConfig(config); }, applyTitle: function(title) { if (!Ext.isString(title) || title.length === 0) { alert('Error: Title must be a valid non-empty string'); } else { return title; } }, applyBottomBar: function(bottomBar) { if (bottomBar && bottomBar.enabled) { if (!this.bottomBar) { return Ext.create('My.own.WindowBottomBar', bottomBar); } else { this.bottomBar.setConfig(bottomBar); } } } }); var myWindow = Ext.create('My.own.Window', { title: 'Hello World', bottomBar: { height: 60 } }); alert(myWindow.getTitle()); // alerts "Hello World" myWindow.setTitle('Something New'); alert(myWindow.getTitle()); // alerts "Something New" myWindow.setTitle(null); // alerts "Error: Title must be a valid non-empty string" myWindow.setBottomBar({ height: 100 }); // Bottom bar's height is changed to 100
Ext.define('Computer', { statics: { instanceCount: 0, factory: function(brand) { // 'this' in static methods refer to the class itself return new this({brand: brand}); } }, config: { brand: null }, constructor: function(config) { this.initConfig(config); // the 'self' property of an instance refers to its class this.self.instanceCount ++; } }); var dellComputer = Computer.factory('Dell'); var appleComputer = Computer.factory('Mac'); alert(appleComputer.getBrand()); // using the auto-generated getter to get the value of a config property. Alerts "Mac" alert(Computer.instanceCount); // Alerts "2"
错误处理与调试
throw new Error('['+ Ext.getDisplayName(arguments.callee) +'] Some message here');