ITPub博客

首页 > 应用开发 > IT综合 > Ext.js4.2.1 Ext.Class

Ext.js4.2.1 Ext.Class

原创 IT综合 作者:百联达 时间:2017-08-16 09:22:54 0 删除 编辑
一:描述


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博客 ” ,链接:https://blog.itpub.net/28624388/viewspace-2143608/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
15年以上互联网经验,先后从事过制造业,证券业,物业行业和物流行业信息系统和互联网产品的设计落地实施,8年系统架构经验。最近关注企业数字化转型、财务数字化服务共享、大语言模型、Kubernetes微服务架构和Istio微服务治理框架。

注册时间:2013-02-05

  • 博文量
    332
  • 访问量
    1265618