在 ExtJS 中调用超类方法的更好方法 [英] Better way to call superclass method in ExtJS

查看:22
本文介绍了在 ExtJS 中调用超类方法的更好方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过的所有 ExtJS 文档和示例都建议像这样调用超类方法:

All the ExtJS documentation and examples I have read suggest calling superclass methods like this:

MyApp.MyPanel = Ext.extend(Ext.Panel, {
  initComponent: function() {
    // do something MyPanel specific here...
    MyApp.MyPanel.superclass.initComponent.call(this);
  }
});

我已经使用这种模式有一段时间了,主要问题是,当您重命名类时,您还必须更改对超类方法的所有调用.这很不方便,我经常会忘记,然后我必须追踪奇怪的错误.

I have been using this pattern for quite some time and the main problem is, that when you rename your class then you also have to change all the calls to superclass methods. That's quite inconvenient, often I will forget and then I have to track down strange errors.

但是阅读 Ext.extend() 的源代码后我发现,我可以使用 superclass()super()Ext.extend() 添加到原型的方法:

But reading the source of Ext.extend() I discovered, that instead I could use the superclass() or super() methods that Ext.extend() adds to the prototype:

MyApp.MyPanel = Ext.extend(Ext.Panel, {
  initComponent: function() {
    // do something MyPanel specific here...
    this.superclass().initComponent.call(this);
  }
});

在此代码中,将 MyPanel 重命名为其他名称很简单 - 我只需要更改一行即可.

In this code renaming MyPanel to something else is simple - I just have to change the one line.

但我有疑问...

  • 我没有在任何地方看到过这种记录,古老的智慧说,我不应该依赖无证行为.

  • I haven't seen this documented anywhere and the old wisdom says, I shouldn't rely on undocumented behaviour.

我在 ExtJS 源代码中没有发现这些 superclass()supr() 方法的单一用途.当您不打算使用它们时,为什么要创建它们?

I didn't found a single use of these superclass() and supr() methods in ExtJS source code. Why create them when you aren't going to use them?

也许这些方法在某些旧版本的 ExtJS 中使用过,但现在已弃用?但它看起来如此有用的功能,你为什么要弃用它?

Maybe these methods were used in some older version of ExtJS but are deprecated now? But it seems such a useful feature, why would you deprecate it?

那么,我应该使用这些方法吗?

So, should I use these methods or not?

推荐答案

确实,supr() 没有记录.我一直期待在 ExtJS 3.0.0 中使用它(Ext 工作人员在论坛中回复,他们已在该版本中添加了它),但它似乎非常糟糕.

Yes indeed, supr() isn't documented. I've been looking forward to using it in ExtJS 3.0.0 (an Ext staff member replied in the forums, they had added it in that version), but it seems horribly broken.

它目前不遍历继承层次结构,而是向上一层,然后卡在这一层,无休止地循环并炸毁堆栈(IIRC).因此,如果您连续有两个或多个 supr(),您的应用程序就会崩溃.我在文档和论坛中都没有找到任何关于 supr() 的有用信息.

It currently does not traverse the inheritance hierarchy, but rather go up one level, then gets stuck on this level, loops endlessly and blows up the stack (IIRC). So, if you have two or more supr() in a row, your app will break. I have not found any useful information on supr() in neither the docs nor the forums.

我不知道维护版本 3.0.x,因为我没有获得支持许可证......

I don't know about the maintenance releases 3.0.x, since I did not get an support license ...

这篇关于在 ExtJS 中调用超类方法的更好方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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