Ext.Class

Files

处理整个框架 类的创建。 这是由Ext.ClassManager使用的底层工厂,不宜直接使用。 如果您选择使用Ext.Class,你将失去命名空间, 混淆和依赖加载功能可通过Ext.ClassManager取得。 你唯一一次使用Ext.Class,是通过Ext.Class直接创建匿名类。

如果你想创建类,你应该使用Ext.define别名Ext.ClassManager.create启用命名空间和动态的依赖分离度。

Ext.Class仅仅是工厂,它不是超类(superclass)的所有。 所有Ext类继承Base类,请参阅Ext.Base

Defined By

Config options

Ext.Class
: String[]
别名 类名称简短的别名列表。多数用于微件定义xtypes: Ext.define('MyApp.CoolPanel', { extend: 'Ext.panel.Panel', alias: ['widget.coo...

别名 类名称简短的别名列表。多数用于微件定义xtypes:

Ext.define('MyApp.CoolPanel', {
    extend: 'Ext.panel.Panel',
    alias: ['widget.coolpanel'],
    title: 'Yeah!'
});

// 使用 Ext.create
Ext.create('widget.coolpanel');

// 使用速记定义微件的xtype
Ext.widget('panel', {
    items: [
        {xtype: 'coolpanel', html: 'Foo'},
        {xtype: 'coolpanel', html: 'Bar'}
    ]
});

除了"微件"的xtype还有"插件"的ftype,"功能"的ptype等别名命名空间。

备用类名 这个类定义备用名称。例如: //开发人员 Ext.define('Developer', { alternateClassName: ['Coder', 'Hacker'], code: function(...

备用类名 这个类定义备用名称。例如:

//开发人员
Ext.define('Developer', {
    alternateClassName: ['Coder', 'Hacker'],
    code: function(msg) {
        alert('Typing... ' + msg);
    }
});

var joe = Ext.create('Developer');
joe.code('stackoverflow'); //栈溢出

var rms = Ext.create('Hacker');//黑客
rms.code('hack hack');
Ext.Class
: Object
配置 配置它们的选项列表默认值,自动产生存取方法。 ...

配置 配置它们的选项列表默认值,自动产生存取方法。 例如:

//构造一台智能手机
Ext.define('SmartPhone', {
     config: {
         hasTouchScreen: false,//有触摸屏
         operatingSystem: 'Other',//操作系统
         price: 500//价格
     },
     constructor: function(cfg) {
         this.initConfig(cfg);
     }
});
//iPhone手机
var iPhone = new SmartPhone({
     hasTouchScreen: true,
     operatingSystem: 'iOS'
});

iPhone.getPrice(); // 500;
iPhone.getOperatingSystem(); // 'iOS'
iPhone.getHasTouchScreen(); // true;
Ext.Class
: String
继承 继承父类。 ...

继承 继承父类。 例如:

//构造人类
Ext.define('Person', {
    say: function(text) { alert(text); }//具有说的方法
});

//构造开发人员

Ext.define('Developer', {
    extend: 'Person',//继承人类
    say: function(text) { this.callParent(["print "+text]); }//继承了说的方法
});
可继承静态 继承这个类的静态方法清单。 ...

可继承静态 继承这个类的静态方法清单。 另外的就像statics 但子类继承这些方法。

Ext.Class
: String[]/Object
混入 混入这个类的类列表。例如: //唱歌 Ext.define('CanSing', { sing: function() { alert("I'm on the highway to hell...我...

混入 混入这个类的类列表。例如:

//唱歌
Ext.define('CanSing', {
     sing: function() {
         alert("I'm on the highway to hell...我在地狱的公路......")
     }
});
//音乐家
Ext.define('Musician', {
     mixins: ['CanSing']
})

在这种情况下的音乐家类将获得的CanSing混入的方法。

但是,如果音乐家已经有'唱'的方法呢?或者你想混入两个类,这两个类都要定义吗? 在这种情况下,它最好定义混入对象,为每个混入指派名称:

//音乐家
Ext.define('Musician', {
     mixins: {
         canSing: 'CanSing'//唱歌
     },

     sing: function() {
         // 唱歌操作委托到混入
         this.mixins.canSing.sing.call(this);
     }
})

音乐家的方法的在这种情况下的将覆盖在方法的混入。 但您可以通过特殊的混入属性,访问有的混合方法。

Ext.Class
: String[]
需要的类列表(数组) 实例化类之前必须加载的类列表 例如: Ext.define('Mother', { requires: ['Child'], giveBirth: function() { //...

需要的类列表(数组) 实例化类之前必须加载的类列表 例如:

Ext.define('Mother', {
    requires: ['Child'],
    giveBirth: function() {
        // 确保Child类是可用的。
        return new Child();
    }
});
Ext.Class
: Boolean
单例 当设置为true,这个类将被实例化为单例。例如: //记录器 Ext.define('Logger', { singleton: true, log: function(msg) { conso...

单例 当设置为true,这个类将被实例化为单例。例如:

//记录器
Ext.define('Logger', {
    singleton: true,
    log: function(msg) {
        console.log(msg);
    }
});

Logger.log('Hello');
Ext.Class
: Object
静态 这个类的静态方法的清单。例如: //构造一台计算机 Ext.define('Computer', { statics: { factory: function(brand) { ...

静态 这个类的静态方法的清单。例如:

 //构造一台计算机
Ext.define('Computer', {
     statics: {
         factory: function(brand) {
             // 'this' 在静态方法中是指类本身
             return new this(brand);
         }
     },

     constructor: function() { ... }//构造函数
});
//创建一台戴尔电脑
var dellComputer = Computer.factory('Dell');
Ext.Class
: String[]
提供可选的类清单,加载相应的类。这些被创建的类不一定是之前加载过的, 但要保证在Ext.onReady之前侦听被调用。 ...

提供可选的类清单,加载相应的类。这些被创建的类不一定是之前加载过的, 但要保证在Ext.onReady之前侦听被调用。 例如:

Ext.define('Mother', {
    uses: ['Child'],
    giveBirth: function() {//生产
        // 此代码可能无法正常工作:
        // return new Child();

        // 改为使用 Ext.create() 
        return Ext.create('Child');
    }
});
Defined By

Properties

Ext.Class
: Arrayprivate

Defaults to: []

Ext.Class
: Objectprivate

Defaults to: {}

Methods

Defined By

Instance Methods

Ext.Class
new( Object data, Function onCreated ) : Ext.Base
构造 创建新的匿名类。 ...

构造 创建新的匿名类。

Parameters

  • data : Object

    代表这个类的对象属性

  • onCreated : Function

    可选,完全创建这个类时要执行的回调函数。 需要注意的是创建过程中,可以是异步的,取决于所使用的预处理器。

Returns

Ext.Class
( Object Class, Object classData, Object onClassCreated )private

Parameters

Ext.Class
( )private

得到预处理器

Ext.Class
( Object Class, Object data, Object hooks )private

Parameters

Ext.Class
( Object Class, Object data, Object onCreated )private

Parameters

Defined By

Static Methods

Ext.Class
( ) : Function[]privatestatic

检索数组栈的默认预处理器

Returns

  • Function[]

    defaultPreprocessors 默认预处理器

Ext.Class
( String name ) : Functionprivatestatic

检索其名称的预处理器的回调函数,在这之前已注册

Parameters

Returns

Ext.Class
( String name, Function fn ) : Ext.Classprivatestatic

注册新的类的创建过程中要使用移除预处理器

Parameters

  • name : String

    预处理器的名称

  • fn : Function

    要执行的回调函数。典型的格式:

    function(cls, data, fn) {
        // 你的代码在这
    
        // 执行此当处理完毕。
        // 异步处理成功
        if (fn) {
            fn.call(this, cls, data);
        }
    });
    

    Parameters

    • cls : Function

      创建类

    • data : Object

      通过属性集在Ext.Class构造

    • fn : Function

      预处理器完成后,无论是否同步处理或异步处理,都必须调用这个回调函数。

Returns

Ext.Class
( String name, String offset, String relativeName ) : Ext.Classprivatestatic

可选择在预处理器堆栈中的具体位置,插入相应的预处理器。 例如:

Ext.Class.registerPreprocessor('debug', function(cls, data, fn) {
    // 你的代码在这

    if (fn) {
        fn.call(this, cls, data);
    }
}).setDefaultPreprocessorPosition('debug', 'last');

Parameters

  • name : String

    预处理器名称。 注意在此之前注册registerPreprocessor

  • offset : String

    插入的位置。四个可能的值是: 'first', 'last', 或者: 'before', 'after' (相对提供的名称在第三个参数)

  • relativeName : String

    相对名称

Returns

Ext.Class
( Array preprocessors ) : Ext.Classprivatestatic

设置默认的预处理器的默认阵列堆叠

Parameters

  • preprocessors : Array

    预处理器

Returns