当前位置:首页 > 开发 > Web前端 > Ext > 正文

initComponent在ext4中的作用

发表于: 2011-09-22   作者:chuanru920   来源:转载   浏览:
摘要: [size=medium]First off, the ability to override via constructor was added in a later version of Ext than initComponent , so all code of a certain age would have to use initComponent. These days, you


[size=medium]First off, the ability to override via constructor was added in a later version of Ext than initComponent , so all code of a certain age would have to use initComponent. These days, you would still override initComponent if you want to do anything after the base class initComponent is called (constructor would be too early for this), but before the component is rendered. In many cases (like the most common, setting up configs), it does not practically matter either way and most people do whatever is most convenient. However, there are some cases where it matters.

 

 

基本知识:object没有prototype;但object有 constructor;constructor是function,所以constructor有prototype。那么原型继承的核心是什么呢?就 是把object的constructor的prototype的属性复制到了此object上。

当然,实际情况要复杂得多,这里提到这些,是因为和Ext的一个方法有关:Ext.extend(parent, config);

其中值得关注的是config。例如这么写:

Ext.ns('Demo','Demo.Configuration');

 

Demo.Configuration.Sample1 = Ext.extend(Ext.Component, {

  name : '李东东',

  otherConfig : {}

  initComponent : function() {

    otherConfig = otherConfig || {sex: 'female'};

  }

});

上面的name和otherConfig属性,在new完第一个Demo.Configuration.Sample1对象之后,就会出现在 Demo.Configuration.Sample1.constructor.prototype的属性之中。也就是说,在new 完第一个对象之后,再new其他的对象时,将会在初始时就自动带了和第一个对象一模一样的属性名值对,这个例子里是{sex : 'female'},注意是在最初始的状态就是这个值,而不再是想当然的到initComponent中才改变的{}了。例子中给otherConfig 赋值是写死的,但实际情况很可能是根据不同的条件动态赋值,这时候这个特性如果不留意,就会很坑人。

转载http://www.cnblogs.com/damnedmoon/archive/2010/05/25/1743706.html


initComponent在ext4中的作用

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号