extjs 类学习

//定义一辆车
Ext.define("Car",{
    extend:"Ext.panel.Panel",
    alias:["widget.benci","widget.bwm"],//定义一个别名 通过 xtype和Ext.widget()创建实例
    run:function(){
    alert("car is running");
    }

});

//通过Ext.widget()创建实例
benci=Ext.widget('benci',{
width : 100,
height : 100
});
benci.run();

//定义一个人
Ext.define('Person', {
requires:["Car"],//require的类必须放在引用前
getCar:function(){
    return Ext.create("Car")
},
//配置选项 有get set方法 相当于封装概念   
config:{age:21,name:"tom"},
//构造类的函数   
constructor: function(cfg) {
//以封装属性来产生新的对象
this.initConfig(cfg);
},   
//可继承的静态的属性和方法  
inheritableStatics : {
sleep : function(){
alert('sleep');
}
},
//对象方法   
say: function(text) { alert(text); },
//对象属性  
address:"city"   
});
//定义一个男孩
Ext.define('Boy', {
//继承Person类 
extend : 'Person'
});

Ext.define("A",{
          //同时继承两个类
           mixins:["Boy","Car"]         
           });



//子类可以通过"类名.方法名"调用父类通过"inheritableStatics"定义的方法
//Person.sleep();
//alert(new Person({age:96,name:"jone"}).getName());
//tom=Ext.create("Boy",{name:"tomer",age:24});
//alert(tom.age);
//new A().say("a");
//car=new Person().getCar();
//car.run();
//alert(new Person().address)

你可能感兴趣的:(ExtJs)