Extjs: extend class via constructor or initComponent?

前端 未结 3 505
小鲜肉
小鲜肉 2021-02-01 19:05

In extjs you can always extend an extjs class via the constructor(). For classes derinving from Component you can also extend via initComponent(

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 19:24

    Here are some relevant quotes from Jay Garcia's book ExtJS in Action:

    initComponent is executed inside the Component class’s constructor, but only after a few crucial setup tasks for the Component have taken place. These tasks include the caching and application of the configuration object properties to the instance of the class

    And later, and in light of constructor being where config parameters get applied to the instance:

    if configured instances of the subclass will ever need to be cloned via the cloneConfig ....then extending via the constructor is the best choice.

    By the way, despite Jay's book being about ExtJS 3 it appears that cloneConfig is still relevant in ExtJS4; see:

    http://docs.sencha.com/ext-js/3-4/#!/api/Ext.Component-method-cloneConfig

    and

    http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Component-method-cloneConfig

提交回复
热议问题