[Ext JS 4] Extjs 之 initComponent 和 constructor的区别
来源:互联网 发布:拯救者y50p优化系统 编辑:程序博客网 时间:2024/06/05 17:32
[Ext JS 4] Extjs 之 initComponent 和 constructor的区别
目录(?)[+]
initComponent 和 constructor是什么
Extjs 提供的组件还是挺丰富的, 但是有时候需求更丰富。
当Extjs 原生的组件无法实现我们的要求的时候, 就需要扩展Extjs 的组件实现自制组件了。
除了这种使用状况, 有时候对于一些相同却有使用很多的配置, 可能像把它独立出来,单独设为一种组件供大家调用, 节省开发时间和提高代码重用度。
initComponent 和 constructor 就是Extjs 提供用来实现继承和扩展的方式。
Ext.define 实现扩展
在Extjs 中使用Ext.define来实现扩展, initComponent 和 constructor的使用方式类似
一般状况上,加上 xtype 的定义, 类似:
(在旧的Extjs 版本中使用 Ext.extend 实现扩展)
那么这两种用法究竟该如何使用? 两者的使用又有什么差别呢?
initComponent 和 constructor区别于联系
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);否则 调用者无法初始化这个对象
sencha 的官网中有一篇针对这两个区别的讨论:
http://www.sencha.com/forum/showthread.php?47210-constructor-Vs-initComponent
不过语法是基于Extjs 3 来讨论的, 笔者觉得作用不是很大。
就笔者实际的开发经验来看, 基本上使用initComponent 就可以达到开发的要求了。
- [Ext JS 4] Extjs 之 initComponent 和 constructor的区别
- [Ext JS 4] Extjs 之 initComponent 和 constructor的区别
- [Ext JS 4] Extjs 之 initComponent 和 constructor的区别
- ExtJS4中initComponent和constructor的区别
- ExtJS4中initComponent和constructor的区别
- Extjs4 initComponent 和 constructor 的一点题目
- combo 添加listeners,使用 initComponent、constructor 的区别
- Ext组件化编程是用initcomponent还是constructor
- ExtJS学习之路第二步:Ext.Component 和 Ext.dom.Element 的区别
- ExtJS Ext.get()和Ext.getCmp()的区别
- constructor与initComponent
- constructor与initComponent
- initComponent还是constructor
- extjs中文解决方案/Eclipse下的js和ext开发
- extjs中文解决方案/Eclipse下的js和ext开发
- ExtJS学习------------基础架构,Extjs.js和Ext-more.js的学习
- 6、ExtJs——Ext基础架构--认识Ext.js和Ext-more.js
- ExtJs--13-- Ext.apply(src,apply) 和 Ext.applyIf(src,apply) 两个方法的使用和区别比较
- 一个倒计时的小工具
- 理解离散傅立叶变换(二) ------实数形式离散傅立叶变换(Real DFT)
- keys
- C中常用的函数
- Android BaseAdapter 和ListAdapter的介绍
- [Ext JS 4] Extjs 之 initComponent 和 constructor的区别
- Eclipse配置Maven
- 数据结构上机测试2-1:单链表操作A
- 视频图像分割研究与实现(二):常见图像和视频分割方法概述
- Android基础入门教程——8.3.17 Canvas API详解(Part 2)剪切方法合集
- KMP的Next函数求解小记
- LeetCode Majority Element
- 从ASCII编码到UNICODE编码
- Log4j 配置示例