ExtJs4使用Ext.define来定义类:
Ext.define( String className, Object data, [Function createdFn] ) : Ext.Base
Ext.define and Ext.ClassManager.create are almost aliasesof each other, with the only exception that Ext.define allows definition of overrides.To avoid trouble, always use Ext.define.
Ext.define('My.awesome.Class', {
someProperty: 'something',
someMethod: function() { ... }
...
}, function() {
alert('Created!');
alert(this === My.awesome.Class); // alerts true
var myInstance = new this();
});
Parameters
- className : String
The class name to create in string dot-namespaced format, for example:
My.very.awesome.Class
,FeedViewer.plugin.CoolPager
. It is highly recommended to follow this simple convention:- The root and the class name are 'CamelCased'
- Everything else is lower-cased
- data : Object
The key-value pairs of properties to apply to this class. Property names can be of any validstrings, except those in the reserved list below:
- createdFn : Function (optional)
callback to execute after the class is created, the execution scope of which(
this
) will be the newly created class itself.
这个方法可以通过extend属性来继承类:
Ext.define('Person', {
say: function(text) { alert(text); }
});
Ext.define('Developer', {
extend: 'Person',
say: function(text) { this.callParent(["print "+text]); }
});