Extjs- Ext.extend函数的使用

Ext.extend在Extjs 中扮演着重大角色,是Extjs中几个重要函数之一。要想深入了解EXTJS,这个函数必须掌握不可,网上有很多关于这个函数的源码分析和介绍。关于这个函数的使用有以下几种情况。

function Base(config) {
  this.name=config.name;
  this.age=config.age;
  this.sex=config.sex;
}

function base(config) {
 this.identity=config.identity;
 this.msg=config.msg;
 this.phone=config.phone;
 
 base.superclass.constructor.call(this,config);
}

Ext.extend(base,Base,{
   showMsg:function(){
     window.alert(this.name+' '+this.age+' '+this.sex+' '+this.identity+' '+this.msg+' '+this.phone);
   }
});

在这种情况下
  1. 1
 var mybase=new base({
       name:’’,
       age:’’,
       sex:’’,
       identity:’’,
       msg:’’,
       phone:’’
 });
  mybase.showMsg();
 此时先调用base constructor函数,随后会调用Base constructor函数,在Extjs中有很多组件就是这样构成继承关系
 第一种情况是子类和父类都存在各自的构造函数

第二种情况是

function Base(config) { 
this.name=config.name; 
this.age=config.age; 
this.sex=config.sex;
 } 
var base=Ext.extend(Base,{
   showMsg:function(){
     window.alert(this.name+' '+this.age+' '+this.sex+' '+this.identity+' '+this.msg+''+this.phone);
   }
}
var mybase=new base( /* */); 将会调用Base constructor函数
 
第三种情况
function Base(config) { 
this.name=config.name; 
this.age=config.age; 
this.sex=config.sex;
 } 
var base=Ext.extend({
constructor:function(config){
   this.identity=config.identity;
   this.msg=config.msg;
  this.phone=config.phone;
},
showMsg:function(){
    window.alert(this.name+' '+this.age+' '+this.sex+' '+this.identity+' '+this.msg+''+this.phone);
  }
}
mockup_2
此时 var mybase= new base( /* */); 将会调用Ext.extend中传入的constructor函数
对Ext.extend使用的三种情况全部分析完了,Extjs中的继承体系都是采用以上三种情况构建成。文章中的文字描述很少。如果你看完些文,不知所解,可以先对Ext.extend函数源码进行分析,在自己多调试几次,再回过头来看,估计一下子就会明白文章意思。画图是使用balsamiq软件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值