PDA

View Full Version : Canuse callParent methods with static function?



bede
13 Mar 2013, 10:47 PM
I meet the error when I run the example code in the Sencha Doc.
Ext.Base.callParent();


Ext.define (http://docs.sencha.com/ext-js/4-1/#!/api/Ext-method-define)('My.Base', { constructor: function (x) { this.x = x; }, statics: { method: function (x) { return x; } } });
Ext.define (http://docs.sencha.com/ext-js/4-1/#!/api/Ext-method-define)('My.Derived2', { extend: 'My.Base', statics: { method: function (x) { return this.callParent([x*2]); // calls My.Base.method } } }); alert(My.Derived2.method(10));Running the above code, firefox will display the error message "TypeError: method.$owner.superclass.#class[method.$name] is null

I found that when change the code from "return this.callParent([x*2]);" to "return x*2;", it can be run.
I wonder to know callparent method can run with static method? If yes, how can I do it?

mitchellsimoens
15 Mar 2013, 11:44 AM
This is working for me:


Ext.define('Class1', {
statics : {
method1 : function () {
console.log('Class1.method1');
}
}
});

Ext.define('Class2', {
extend : 'Class1',

statics : {
method1 : function () {
console.log('Class2.method1');

this.callParent();
}
}
});

Class2.method1();