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方法html

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

在  constructor方法中调用了initComponentthis

2.spa

   1)自定义类中的 initComponent 函数中必须调用 callParent();不然 调用者没法初始化这个对象.net

   2)针对button 这样的扩展组件来讲,自定义类中的  constructor ,须要调用callParent( arguments);不然 调用者没法初始化这个对象orm

[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,以确保父类的构造函数在子类的做用域里工做。xml

相关文章
相关标签/搜索