Files
在整个框架,Ext.ClassManager类管理字符串的类名称映射到实际类的对象。 一般不直接访问它,而是通过以下这些方法(方便记忆):
Ext.define(className, properties);
属性
是一个对象代表了应用类的属性集合。
参见create 更详细的说明。
//构造人类
Ext.define('Person', {
name: 'Unknown',//不知道姓名
//构造
constructor: function(name) {
if (name) {
this.name = name;
}
},
//吃
eat: function(foodType) {
alert("我吃:" + foodType);
return this;
}
});
var aaron = new Person("Aaron");//姓名:Aaron
aaron.eat("Sandwich"); // alert("我吃:三明治");
Ext.Class拥有一套功能强大的可扩展的pre-processors类的创建有关的一切保护, 包括但不限于继承,混入,配置,静态等
//开发人员
Ext.define('Developer', {
extend: 'Person',// 人类
constructor: function(name, isGeek) {
this.isGeek = isGeek;
// 适用于从父类的原型方法
this.callParent([name]);
},
code: function(language) {
alert("I'm coding in: " + language);
this.eat("Bugs");
return this;
}
});
var jacky = new Developer("Jacky", true);//杰克
jacky.code("JavaScript"); // alert("我编写的: JavaScript");
// alert("我消灭: Bugs");
调用父类的方法的更多细节,请参阅Ext.Base.callParent
//演奏吉他
Ext.define('CanPlayGuitar', {
playGuitar: function() {
alert("F#...G...D...A");
}
});
//写歌词
Ext.define('CanComposeSongs', {
composeSongs: function() { ... }
});
//唱歌
Ext.define('CanSing', {
sing: function() {
alert("你知道不知道 知不知道 我等到花儿也谢了...")
}
});
//音乐家
Ext.define('Musician', {
extend: 'Person',//人类
mixins: {
canPlayGuitar: 'CanPlayGuitar',//弹吉他
canComposeSongs: 'CanComposeSongs',//写歌词
canSing: 'CanSing'//唱歌
}
})
//很酷的人
Ext.define('CoolPerson', {
extend: 'Person',//人类
mixins: {
canPlayGuitar: 'CanPlayGuitar',//弹吉他
canSing: 'CanSing'//唱歌
},
sing: function() {
alert("啊哈....");
this.mixins.canSing.sing.call(this);
alert("[在同一时间玩吉他...]");
this.playGuitar();
}
});
var me = new CoolPerson("Jacky");//杰克
me.sing(); // alert("啊哈...");
// alert("你知不知道 知不知道 我等到花儿也谢了...");
// alert("[在同一时间玩吉他...]");
// alert("F#...G...D...A");
//智能手机
Ext.define('SmartPhone', {
config: {
hasTouchScreen: false,//触摸屏
operatingSystem: 'Other',//操作系统
price: 500
},
isExpensive: false,//价格昂贵
constructor: function(config) {
this.initConfig(config);
},
applyPrice: function(price) {
this.isExpensive = (price > 500);
return price;
},
//应用操作系统
applyOperatingSystem: function(operatingSystem) {
if (!(/^(iOS|Android|BlackBerry)$/i).test(operatingSystem)) {//苹果iOS/安卓/黑莓
return 'Other';
}
return operatingSystem;
}
});
//iPhone手机
var iPhone = new SmartPhone({
hasTouchScreen: true,//智能手机
operatingSystem: 'iOS'//操作系统
});
iPhone.getPrice(); // 500;
iPhone.getOperatingSystem(); // 'iOS'
iPhone.getHasTouchScreen(); // true;
iPhone.hasTouchScreen(); // true
iPhone.isExpensive; // false;
iPhone.setPrice(600);
iPhone.getPrice(); // 600
iPhone.isExpensive; // true;
iPhone.setOperatingSystem('AlienOS');
iPhone.getOperatingSystem(); // 'Other' 其他
Ext.define('Computer', {
statics: {
factory: function(brand) {
// 'this' 在静态方法中指向类本身
return new this(brand);
}
},
constructor: function() { ... }
});
//戴尔电脑
var dellComputer = Computer.factory('Dell');
在类方法访问静态属性,另请参见更多的细节Ext.Base.statics和Ext.Base.self 单例
类 所有类通过ClassManager定义。 键的类的名称和值是对类的引用。
Defaults to: {}
创建侦听器
Defaults to: []
默认的后置处理器
Defaults to: []
启用命名空间解析缓存
Defaults to: true
存在的缓存
Defaults to: {}
实例化
Defaults to: []
地图
Defaults to: {alternateToName: {}, aliasToName: {}, nameToAliases: {}, nameToAlternates: {}}
创建侦听器名称
Defaults to: {}
命名空间解析缓存
Defaults to: {}
命名空间重写
命名空间重写
后置处理器
Defaults to: {}
创建Ext.ns,支持命名空间重写
获取所提供的对象类; 如果它不是任意Ext.define创建的类的一个实例,则返回null。 一般是调用简写Ext.getClass
var component = new Ext.Component();
Ext.ClassManager.getClass(component); // returns Ext.Component
对象
class 对象类
根据其引用的类或它的实例获取名称; 一般是调用简写 Ext.getClassName
Ext.ClassManager.getName(Ext.Action); // returns "Ext.Action"
className 类名
将一个字符串表达式转换到数组匹配的类名。 表达式可以是指类的别名或类名。表达式支持通配符:
// returns ['Ext.window.Window']
var window = Ext.ClassManager.getNamesByExpression('widget.window');
// returns ['widget.panel', 'widget.window', ...]
var allWidgets = Ext.ClassManager.getNamesByExpression('widget.*');
// returns ['Ext.data.Store', 'Ext.data.ArrayProxy', ...]
var allData = Ext.ClassManager.getNamesByExpression('Ext.data.*');
表达式
classNames 类名
实例化
实例化类的别名; 一般是调用简写 Ext.createByAlias 如果Ext.Loader类 和enabled类 还没有被定义, 它会尝试通过同步加载类。
var window = Ext.ClassManager.instantiateByAlias('widget.window', { width: 600, height: 800, ... });
instance 例子
在堆栈中的特定位置插入后置处理器 可选相对于所有现有的后置处理器
后置处理器的名称。 需要注意的是在此之前它需要被registerPostprocessor注册
偏移插入位置。四个可能的值有: 'first', 'last', or: 'before', 'after' (第三个参数中提供的名称)
相对的名称
this
创建命名空间,并分配 value
创建的对象
Ext.ClassManager.setNamespace('MyCompany.pkg.Example', someObject);
alert(MyCompany.pkg.Example === someObject); // alerts true 提示 true