How to add a method to singleton in ExtJS4?

This is the ExtJS Shape Class :

Ext.define('Ext.chart.Shape', {

    singleton: true,

    circle: function (surface, opts) {
        return surface.add(Ext.apply({
            type: 'circle',
            x: opts.x,
            y: opts.y,
            stroke: null,
            radius: opts.radius
        }, opts));
    },
    ...
});

I want to add a method to this class. For instance:

myCircle: function (surface, opts) {
        return ...
},

How can i do this?

+3
source share
2 answers

I have found the answer. This solution if someone needs it:

Ext.define('MyShape', {
    override: 'Ext.chart.Shape',

    initialize: function() {
        this.callOverridden(arguments);
    },

    myCircle: function (surface, opts) {
        return ...
    }
});
+3
source

You can expand to add new functions or override to change the behavior of existing functions in the class. The links below are for more information in the sencha documentation explaining how to use them.

Extend

Override

An example implementation of the extension:

Ext.define('yourCustomClassHere', {
    extend: 'Ext.chart.Shape',
    newFunctionName: function () {
       //your function here
    }
});
+2
source

All Articles