Extjs 之 initComponent 和 constructor的区别(转)

在创建自定义类时,先构造(constructor)后初始化(initComponent)。如:
(在旧的Extjs 版本中使用 Ext.extend 实现扩展)

Ext.define('Btn',{
extend:'Ext.button.Button',
initComponent:function(){
alert('后初始化部件启动...');
},
constructor:function(){
this.text = new Date();
this.renderTo = Ext.getBody();
this.callParent();
alert('先构造函数启动...');
}
});

Ext.onReady(function(){
Ext.create('Btn');
});

initComponent是在construor里被调用,constructor是在其他地方调用;一个用于具体的创建控件,一个是用于创建控件对象


http://blog.csdn.net/oscar999/article/details/33743171

1. initComponent这个方法是在Ext.Component的构造函数(constructor)中调用的,只有直接或间接继承自 Ext.Component的类才会在constructor里调用initComponent方法

看一下  Ext.AbstractComponent的源码文件 src/AbstractComponent.js

在  constructor方法中调用了initComponent

2.

   1)自定义类中的 initComponent 函数中必须调用 callParent();否则 调用者无法初始化这个对象

   2)针对button 这样的扩展组件来说,自定义类中的  constructor ,需要调用callParent( arguments);否则 调用者无法初始化这个对象

[html] view plain copy
  1. this.callParent(arguments);  
这里的arguments 是需要的。

 

(在Extjs 4 之前的版本中, 可能会看到比较多的XXX.superclass.constructor.call 写法)



http://blog.csdn.net/alastormoody/article/details/8251018

Extjs之superclass.constructor.call(this)之理解

Ext.extend()函数提供了直接访问父类构造函数的途径,通过 SubClass.superclass.constructor.call(this);就可以直接调用父类的构造函数,这个函数的第一个参数总是 this,以确保父类的构造函数在子类的作用域里工作。




转载于:https://www.cnblogs.com/givemeanorange/p/5570214.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值