Ext singleton
- Ext.onReady(function(){
- new Ext.Component({
- renderTo: document.body,
- html: 'DOM ready!'
- });
- });
------------------------------------------------------------------------------------
create( [String name], [Object... args] ) : Object
Instantiate a class by either full name, alias or alternate name.用类的完整名字,别名或者是可选的名字创建对象实例
If Ext.Loader is enabled and the class has not been defined yet, it will attempt to load the class via synchronous loading.(如果ext装载机是启用并哟啊创建的类没有定义,但它将尝试通过同步加载类。)
For example, all these three lines return the same result:(例如,下面三行将返回相同的结果:)
- Ext.onReady(function(){
- // alias
- var window1 = Ext.create('widget.window', {
- title:'window1',
- width: 600,
- height: 100,
- //...
- });
- window1.show();
- // alternate name
- var window2 = Ext.create('Ext.Window', {
- title:'window2',
- width: 600,
- height: 100,
- //...
- });
- window2.show();
- // full class name
- var window3 = Ext.create('Ext.window.Window', {
- title:'window3',
- width: 600,
- height: 100,
- //...
- });
- window3.show();
- // single object with xclass property:
- var window4 = Ext.create({
- xclass: 'Ext.window.Window', // any valid value for 'name' (above)
- title:'window4',
- width: 600,
- height: 100,
- //...
- });
- window4.show();
- // full class name
- var window5 = Ext.create('Ext.window.Window', {
- title:'window5',
- width: 600,
- height: 100
- // ...
- });
- window5.show();
- });
Parameters
name : String (optional)
The class name or alias. Can be specified as xclass property if only one object parameter is specified.(类名或者别名。如果一个对象属性指定了,就可以指定xclass属性)
args : Object... (optional)
Additional arguments after the name will be passed to the class' constructor.(名字后面的附加参数会传递给类的构造函数。)
Returns
Object
instance
---------------------------------------------------------
define( String className, Object data, Function createdFn ) : Ext.Base
Defines a class or override. A basic class is defined like this:(定义一个类或者重载。一个基本类是像下面这样定义的:)
- Ext.onReady(function(){
- Ext.define('My.awesome.Class', {
- someProperty: 'something',
- someMethod: function(s) {
- alert(s + this.someProperty);
- }
- //...
- });
- var obj = new My.awesome.Class();
- obj.someMethod('Say '); // alerts 'Say something'
- });
To defines an override, include the override property.(重载类,包括重载属性) The content of an override is aggregated with the specified class in order to extend or modify that class. (重载类将会聚合指定类以去扩展和修改类)This can be as simple as setting default property values or it can extend and/or replace methods.(这和设置默认的属性值一样简单,或者它可以拓展或替换方法) This can also extend the statics of the class.(这也可以拓展类静态的方法和属性)
One use for an override is to break a large class into manageable pieces.(重载的一个用途就是把一个很大的类分成可以管理的各个部分。)
- // File: /src/app/Panel.js
- Ext.define('My.app.Panel', {
- extend: 'Ext.panel.Panel',
- requires: [
- 'My.app.PanelPart2',
- 'My.app.PanelPart3'
- ]
- constructor: function (config) {
- this.callParent(arguments); // calls Ext.panel.Panel's constructor
- //...
- },
- statics: {
- method: function () {
- return 'abc';
- }
- }
- });
- // File: /src/app/PanelPart2.js
- Ext.define('My.app.PanelPart2', {
- override: 'My.app.Panel',
- constructor: function (config) {
- this.callParent(arguments); // calls My.app.Panel's constructor
- //...
- }
- });
Another use of overrides is to provide optional parts of classes that can be independently required. In this case, the class may even be unaware of the override altogether.(重载类的另一个用途就是提供单独要求的可选的类的部分,在这样的例子中,类甚至不能意识到已经重载了。)
- Ext.define('My.ux.CoolTip', {
- override: 'Ext.tip.ToolTip',
- constructor: function (config) {
- this.callParent(arguments); // calls Ext.tip.ToolTip's constructor
- //...
- }
- });
The above override can now be required as normal.
- Ext.define('My.app.App', {
- requires: [
- 'My.ux.CoolTip'
- ]
- });
Overrides can also contain statics:
- Ext.define('My.app.BarMod', {
- override: 'Ext.foo.Bar',
- statics: {
- method: function (x) {
- return this.callParent([x * 2]); // call Ext.foo.Bar.method
- }
- }
- });
IMPORTANT: An override is only included in a build if the class it overrides is required. Otherwise, the override, like the target class, is not included.(如果被重载的类在重载的时候是要求的,重载在编译的时候就会包含进来。否则的话,重载,例如目标类是不会被包含进来的)
Parameters
className : String
The class name to create in string dot-namespaced format, for example: 'My.very.awesome.Class', 'FeedViewer.plugin.CoolPager'(创建的类名使用字符串点-命名空间的格式,例如'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 valid strings, except those in the reserved listed below: - mixins - statics - config - alias - self - singleton - alternateClassName - override(属性名可以是任何合法的字符,出了下面提供的列表- mixins - statics - config - alias - self - singleton - alternateClassName - override)
createdFn : Function
Optional callback to execute after the class is created, the execution scope of which (this) will be the newly created class itself.(在类创建之后执行可选的回调方法,这个指定的范围将会是新创建的类的自身)
Returns
Ext.Base
-----------------------------------------------------------------------------------
apply( Object object, Object config, [Object defaults] ) : Object
Copies all the properties of config to the specified object. Note that if recursive merging and cloning without referencing the original objects / arrays is needed, use Ext.Object.merge instead.
(拷贝配置中的所有属性到一个指定的对象中。注意到如果递归合并和没有拷贝原始对象和数组的引用,可以使用Ext.Object.merge)
Parameters
object : Object
The receiver of the properties(接受属性的对象)
config : Object
The source of the properties(被拷贝属性的对象)
defaults : Object (optional)
A different object that will also be applied for default values(另一个将要使用默认值的对象)
Returns
Object
returns obj
1111111