1. #1
    Sencha User
    Join Date
    Nov 2007
    Posts
    8
    Vote Rating
    0
    chunkT is on a distinguished road

      0  

    Question Unanswered: Ext.extend defined in Class does not work like the old Ext.extend defined in Ext

    Hi all,

    i try to upgrade to ExtJS 4.* and have figured out that the extend mechanism for classes does not work as aspected when using Ext.extend; I am aware of the fact that this function is deprecated and that i should use Ext.define but i am curios if the following behavior is intentional or not.

    Previous to ExtJS 4 i had some classes defined the following way:

    PHP Code:
    MyClass = function(){
        
    console.log('MyClass.constructor');
        
    this.addEvents('dosomething');
        
    MyClass.superclass.constructor.call(this);
    };

    Ext.extend(MyClassExt.util.Observable, {
      
    doSomething : function(){
      
      }
    });
    new 
    MyClass() //logs MyClass.constructor

    //creating a new SubClass from MyClass

    MySubClass Ext.extend(MyClass, {
        
    constructor : function(){
            
    console.log('MySubClass.constructor');
            
    MySubClass.superclass.constructor.call(this);
        }
    });

    new 
    MySubClass()
    //logs MySubClass.constructor then MyClass.constructor in Ext < 4
    //logs MySubClass.constructor in Ext >= 4 
    Since ExtJS 4 the constructor of MyClass is not called anymore.
    Is this considered a bug or a feature? :]

    Best,
    chunk

  2. #2
    Ext JS Premium Member burnnat's Avatar
    Join Date
    Jun 2011
    Posts
    418
    Vote Rating
    63
    Answers
    42
    burnnat is just really nice burnnat is just really nice burnnat is just really nice burnnat is just really nice

      0  

    Default

    The functionality you're looking for does exist in ExtJS 4. In fact, calling superclass constructors and methods is even easier than it was previously - all you have to do is use this.callParent() and pass an array of arguments to use. Here's a modified version of your example that will work in ExtJS 4:
    Code:
    Ext.define('MyClass', {
        constructor: function() {
            console.log('MyClass.constructor');
        }
    });
    
    Ext.define('MySubClass', {
        extend: 'MyClass',
        
        constructor: function() {
            console.log('MySubClass.constructor');
            this.callParent(arguments);
        }
    })
    
    Ext.create('MySubClass');

Thread Participants: 1