I have a super class in my application, that defines an object like this:
Ext.define('superclass', {
    myObject: {
        prop1: true,
        prop2: 200,
        ..
    }
and a child class that inherited the superclass above, that declares the same object:
Ext.define('childclass', {
    extend: 'superclass',
    myObject: {
        prop3: false,
        prop4: false,
        ..
    }
The problem is with that, the myObject in the child class has only the prop3 and prop4 properties.
I need that myObject ib child class has all prop1, prop2, prop3 and prop4 properties.
How can I do this ?
Extend the object in the constructor (or in initComponent if you extend Ext.Component):
Ext.define('childclass', {
    extend: 'superclass',
    constructor: function() {
        this.myObject = Ext.apply({}, this.myObject, {
            prop3: false,
            prop4: false
        });
        this.callParent(arguments);
    }
});
Demo.
Both of the provided answers will change the superclass prototype's myObject property as soon as a child class is constructed. This may not be what you want. I question why you are putting an object on the class prototype like this. It's generally not a good idea to do it. But if you really want to, you can do this
Ext.define('childclass', {
    extend: 'superclass',
    // I'm adding an empty object here so that myObject on the
    // prototype does not get overridden.
    myObject: Ext.merge({}, superclass.prototype.myObject, {
        prop3: false,
        prop4: false
    });
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With