Extjs:通过构造函数或 initComponent 扩展类? [英] Extjs: extend class via constructor or initComponent?

查看:27
本文介绍了Extjs:通过构造函数或 initComponent 扩展类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 extjs 中,您始终可以通过 constructor() 扩展 extjs 类.对于从 Component 派生的类,您还可以通过 initComponent() 进行扩展.

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

我想知道为什么这么多代码通过 initComponent 扩展,而 constructor 似乎是通用的扩展方法.initComponent 是否比 constructor 有明显的优势?

I am wondering why so many code extend via initComponent, whereas constructor seems to be the universal extension method. Does initComponent offer clear advantage over constructor?

推荐答案

首先,通过 constructor 覆盖的能力是在比 initComponent 更高的 Ext 版本中添加的,所以某个时代的所有代码都必须使用 initComponent.现在,如果您想在调用基类 initComponent 之后做任何事情(构造函数为时过早),您仍然会覆盖 initComponent,但是 之前 组件是呈现.在许多情况下(如最常见的设置配置),无论哪种方式实际上都无关紧要,大多数人会做最方便的事情.但是,在某些情况下它很重要.

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.

这篇关于Extjs:通过构造函数或 initComponent 扩展类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆