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

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

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.

我一直在使用这种模式很长一段时间,主要的问题是,当你重命名你的类时,你还必须改变所有对超类方法的调用。这很不方便,我常常会忘记,然后我必须追查奇怪的错误。

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:

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

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

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

在这段代码中,将MyPanel重命名为其他东西很简单 - 我只需更改一行。

But I have doubts...

但我怀疑......

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

    我没有在任何地方看到过这种情况,旧的智慧说,我不应该依赖无证的行为。

  • 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源代码中单独使用这些superclass()和supr()方法。为什么在你不打算使用它们时创建它们?

  • 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?

    也许这些方法在某些旧版本的ExtJS中使用但现在已被弃用?但它似乎是一个非常有用的功能,你为什么要弃用呢?

So, should I use these methods or not?

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

6 个解决方案

#1


13

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.

是的,supr()没有记录。我一直期待在ExtJS 3.0.0中使用它(一个Ext工作人员在论坛中回复,他们已经在该版本中添加了它),但它看起来非常糟糕。

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.

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

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

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

更多相关文章

  1. contains和compareDocumentPosition 方法来确定是否HTML节点间的
  2. arcgis api for js入门开发系列十 自定义Navigation控件样式风格
  3. 控制台在node . js中没有“debug”方法吗?
  4. 利用javascript动态加载头部出现点击事件与hover事件无效解决方
  5. 类似jQuery的extend扩展方法的实现
  6. 如何在onchange()事件后调用的方法中将焦点设置为输入字段?
  7. jsPDF中使用.text()方法的字母间距
  8. javascript 截取字符串方法汇总
  9. 关于JavaScript方法,设置GridView中首项CheckBox勾选,整列全部勾选

随机推荐

  1. PHP 有趣的经典算法
  2. PHP魔术方法之__iset,__unset详解(代码实
  3. php中session时间设置浅析
  4. PHP 与 Go 的语法区别
  5. PHP面向对象之接口详解(代码实例)
  6. PHP中正则表达式详解(代码实例)
  7. 面向对象中什么是封装
  8. php中的接口与抽象类及接口与抽象类的区
  9. php如何实现header跳转
  10. PHP中面向对象之Final关键字详解(代码实