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

问题描述

在extj中,您可以随时通过构造函数()来扩展一个extjs类。对于从组件中衍生的类,您还可以通过 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 扩展,而构造函数似乎是通用扩展方法。 initComponent 构造函数提供明确的优势?

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?

推荐答案

首先,通过构造函数重写的能力被添加到更高版本的Ext中,而不是 initComponent ,所以一定年龄的所有代码都必须使用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来扩展类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 10:35