Note that there are some explanatory texts on larger screens.

plurals
  1. POBetter way to call superclass method in ExtJS
    primarykey
    data
    text
    <p>All the ExtJS documentation and examples I have read suggest calling superclass methods like this:</p> <pre><code>MyApp.MyPanel = Ext.extend(Ext.Panel, { initComponent: function() { // do something MyPanel specific here... MyApp.MyPanel.superclass.initComponent.call(this); } }); </code></pre> <p>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.</p> <p>But reading the source of <code>Ext.extend()</code> I discovered, that instead I could use the <code>superclass()</code> or <code>super()</code> methods that <code>Ext.extend()</code> adds to the prototype:</p> <pre><code>MyApp.MyPanel = Ext.extend(Ext.Panel, { initComponent: function() { // do something MyPanel specific here... this.superclass().initComponent.call(this); } }); </code></pre> <p>In this code renaming MyPanel to something else is simple - I just have to change the one line.</p> <p>But I have doubts...</p> <ul> <li><p>I haven't seen this documented anywhere and the old wisdom says, I shouldn't rely on undocumented behaviour.</p></li> <li><p>I didn't found a single use of these <code>superclass()</code> and <code>supr()</code> methods in ExtJS source code. Why create them when you aren't going to use them?</p></li> <li><p>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?</p></li> </ul> <p>So, should I use these methods or not?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload