Ext.js4.2.1 Ext.Class

一:描述


Ext.Class 是一个低层级的工厂类,被Ext.ClassManager使用,一般不直接使用Ext.Class,除非在创建一个匿名类时使用。


如果要创建一个类时请使用Ext.define 它是Ext.ClassManager.create的别名。


Ext.Class是一个工厂类,不是任何类的父类。 所有类的基类是 Ext.Base




二:Config


1.alias 简称/别名


如: 


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


// Using Ext.create
Ext.create('widget.coolpanel');


// Using the shorthand for defining widgets by xtype
Ext.widget('panel', {
    items: [
        {xtype: 'coolpanel', html: 'Foo'},
        {xtype: 'coolpanel', html: 'Bar'}
    ]
});


2.alternateClassName 可选名


如:


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');


3.config  具有默认值的配置参数


如:


Ext.define('SmartPhone', {
     config: {
         hasTouchScreen: false,
         operatingSystem: 'Other',
         price: 500
     },
     constructor: function(cfg) {
         this.initConfig(cfg);
     }
});


var iPhone = new SmartPhone({
     hasTouchScreen: true,
     operatingSystem: 'iOS'
});


iPhone.getPrice(); // 500;
iPhone.getOperatingSystem(); // 'iOS'
iPhone.getHasTouchScreen(); // true;


4.extend  继承,当前类的父类


如:


Ext.define('Person', {
    say: function(text) { alert(text); }
});


Ext.define('Developer', {
    extend: 'Person',
    say: function(text) { this.callParent(["print "+text]); }
});


5.inheritableStatics  可继承的静态方法


6.statics  不可继承的静态方法


如:


Ext.define('Computer', {
     statics: {
         factory: function(brand) {
             // 'this' in static methods refer to the class itself
             return new this(brand);
         }
     },


     constructor: function() { ... }
});


var dellComputer = Computer.factory('Dell');


7.mixins  把其它类糅合进当前类


如:


Ext.define('CanSing', {
     sing: function() {
         alert("I'm on the highway to hell...")
     }
});


Ext.define('Musician', {
     mixins: ['CanSing']
})


此时Musician就会拥有一个sing的方法,通过CanSing类mixin而来。




如果,Musician本身已经有了一个sing方法,应该如下操作:


Ext.define('Musician', {
     mixins: {
         canSing: 'CanSing'
     },


     sing: function() {
         // delegate singing operation to mixin
         this.mixins.canSing.sing.call(this);
     }
})




8.requires  当前类加载之前需要加载的类,类似于import


如:


Ext.define('Mother', {
    requires: ['Child'],
    giveBirth: function() {
        // we can be sure that child class is available.
        return new Child();
    }
});


9.singleton  单例模式


10.uses  和当前类一起加载的类,不是必须的类


如:


Ext.define('Mother', {
    uses: ['Child'],
    giveBirth: function() {
        // This code might, or might not work:
        // return new Child();


        // Instead use Ext.create() to load the class at the spot if not loaded already:
        return Ext.create('Child');
    }
});


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28624388/viewspace-2143608/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28624388/viewspace-2143608/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值