I encountered some strange behaviour while going through an example of the ST2 class system. I define a base class and then extend it, using an applier method in the subclass to extend the base class' getter, as follows:
If I never instantiate the base class and only instantiate the subclass, the subclass' getter method is called as expected and "Subclass: value" is displayed. However, if I do instantiate the base class first, calling the getter method on the subclass instance returns the base class' result, so just "value" is displayed.
Code:
Ext.define('MyApp.test.BaseClass', {
extend: 'Ext.Component',
config: {
property: 'value'
},
constructor: function () {
this.callParent();
}
});
Ext.define('MyApp.test.SubClass', {
extend: 'MyApp.test.BaseClass',
config: {
anotherProperty: 'another value'
},
constructor: function () {
this.callParent(arguments);
},
applyProperty: function (property) {
return 'Subclass: ' + property;
}
});
var base = Ext.create('MyApp.test.BaseClass'); // problem?
var sub = Ext.create('MyApp.test.SubClass');
alert(sub.getProperty());
If I never instantiate the base class and only instantiate the subclass, the subclass' getter method is called as expected and "Subclass: value" is displayed. However, if I do instantiate the base class first, calling the getter method on the subclass instance returns the base class' result, so just "value" is displayed.
Why does instantiating the base class affect the subclass instance? What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire