Sencha Documentation

The root of all classes created with Ext.define All prototype and static properties of this class are inherited by any other class

Properties

 
self : Class
Get the reference to the current class from which this object was instantiated. Unlike Ext.Base.statics, `this.self` ...

Get the reference to the current class from which this object was instantiated. Unlike Ext.Base.statics, this.self is scope-dependent and it's meant to be used for dynamic inheritance. See Ext.Base.statics for a detailed comparison

Ext.define('My.Cat', {
    statics: {
        speciciesName: 'Cat' // My.Cat.speciciesName = 'Cat'
    },

    constructor: function() {
        alert(this.self.speciciesName); / dependent on 'this'

        return this;
    },

    clone: function() {
        return new this.self();
    }
});


Ext.define('My.SnowLeopard', {
    extend: 'My.Cat',
    statics: {
        speciciesName: 'Snow Leopard' // My.SnowLeopard.speciciesName = 'Snow Leopard'
    }
});

var kitty = new My.Cat();           // alerts 'Cat'
var katty = new My.SnowLeopard();   // alerts 'Snow Leopard'

var cutie = katty.clone();
alert(Ext.getClassName(cutie));     // alerts 'My.SnowLeopard'

Methods

 
callOverridden( Array/Arguments args ) : Mixed
Call the original method that was previously overridden with Ext.Base.override Ext.define('My.Cat', { co...

Call the original method that was previously overridden with Ext.Base.override

Ext.define('My.Cat', {
    constructor: function() {
        alert("I'm a cat!");

        return this;
    }
});

My.Cat.override({
    constructor: function() {
        alert("I'm going to be a cat!");

        var instance = this.callOverridden();

        alert("Meeeeoooowwww");

        return instance;
    }
});

var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
                          // alerts "I'm a cat!"
                          // alerts "Meeeeoooowwww"

Parameters

  • args : Array/Arguments

    The arguments, either an array or the arguments object

Returns

  • Mixed   Returns the result after calling the overridden method
 
callParent( Array/Arguments args ) : Mixed
Call the overridden superclass' method. For example: Ext.define('My.own.A', { constructor: function(test...

Call the overridden superclass' method. For example:

Ext.define('My.own.A', {
    constructor: function(test) {
        alert(test);
    }
});

Ext.define('My.own.B', {
    constructor: function(test) {
        alert(test);

        this.callParent([test + 1]);
    }
});

var a = new My.own.A(1); // alerts '1'
var b = new My.own.B(1); // alerts '1', then alerts '2'

Parameters

  • args : Array/Arguments

    The arguments, either an array or the arguments object from the current method, for example: this.callParent(arguments)

Returns

  • Mixed   Returns the result from the superclass' method
 
constructor : Object
Default constructor, simply returns `this`
Default constructor, simply returns `this`
 
createAlias( String/Object alias, String/Object origin ) : Void
Create aliases for current prototype methods. Example: Ext.define('My.cool.Class', { method1: function()...

Create aliases for current prototype methods. Example:

Ext.define('My.cool.Class', {
    method1: function() { ... },
    method2: function() { ... }
});

var test = new My.cool.Class();

My.cool.Class.createAlias({
    method3: 'method1',
    method4: 'method2'
});

test.method3(); // test.method1()

My.cool.Class.createAlias('method5', 'method3');

test.method5(); // test.method3() -> test.method1()

Parameters

  • alias : String/Object

    The new method name, or an object to set multiple aliases. See flexSetter

  • origin : String/Object

    The original method name

Returns

  • Void
 
extend( String/Object name, Mixed value ) : Void
Add / override static properties of this class. This method is a flexSetter. It can either accept an object of key - ...

Add / override static properties of this class. This method is a flexSetter. It can either accept an object of key - value pairs or 2 arguments of name - value.

Ext.define('My.cool.Class', {
    ...
});

My.cool.Class.extend({
    someProperty: 'someValue',      // My.cool.Class.someProperty = 'someValue'
    method1: function() { ... },    // My.cool.Class.method1 = function() { ... };
    method2: function() { ... }     // My.cool.Class.method2 = function() { ... };
});

My.cool.Class.extend('method3', function(){ ... }); // My.cool.Class.method3 = function() { ... };

Parameters

Returns

  • Void
 
implement( String/Object name, Mixed value ) : Void
Add / override prototype properties of this class. This method is a flexSetter. It can either accept an object of key...
Add / override prototype properties of this class. This method is a flexSetter. It can either accept an object of key - value pairs or 2 arguments of name - value. Ext.define('My.cool.Class', { ... }); // Object with key - value pairs My.cool.Class.implement({ someProperty: 'someValue', method1: function() { ... }, method2: function() { ... } }); var cool = new My.cool.Class(); alert(cool.someProperty); // alerts 'someValue' cool.method1(); cool.method2(); // name - value arguments My.cool.Class.implement('method3', function(){ ... }); cool.method3();

Parameters

Returns

  • Void
 
initConfig( Object config ) : Object
Initialize configuration for this class. a typical example: Ext.define('My.awesome.Class', { // The defa...
Initialize configuration for this class. a typical example: Ext.define('My.awesome.Class', { // The default config config: { name: 'Awesome', isAwesome: true }, constructor: function(config) { this.initConfig(config); return this; } }); var awesome = new My.awesome.Class({ name: 'Super Awesome' }); alert(awesome.getName()); // 'Super Awesome'

Parameters

  • config : Object

Returns

  • Object   mixins The mixin prototypes as key - value pairs
 
override( String/Object name, Mixed value ) : Void
Add / override prototype properties of this class. This method is similar to implement, except that it stores the ref...
Add / override prototype properties of this class. This method is similar to implement, except that it stores the reference of the overridden method which can be called later on via Ext.Base.callOverridden

Parameters

Returns

  • Void
 
statics : Class
Get the reference to the class from which this object was instantiated. Note that unlike Ext.Base.self, `this.statics...

Get the reference to the class from which this object was instantiated. Note that unlike Ext.Base.self, this.statics() is scope-independent and it always returns the class from which it was called, regardless of what this points to during runtime

Ext.define('My.Cat', {
    statics: {
        speciciesName: 'Cat' // My.Cat.speciciesName = 'Cat'
    },

    constructor: function() {
        alert(this.statics().speciciesName); // always equals to 'Cat' no matter what 'this' refers to
                                             // equivalent to: My.Cat.speciciesName

        alert(this.self.speciciesName);      // dependent on 'this'

        return this;
    },

    clone: function() {
        var cloned = new this.self;                      // dependent on 'this'

        cloned.groupName = this.statics().speciciesName; // equivalent to: My.Cat.speciciesName

        return cloned;
    }
});


Ext.define('My.SnowLeopard', {
    statics: {
        speciciesName: 'Snow Leopard' // My.SnowLeopard.speciciesName = 'Snow Leopard'
    },

    constructor: function() {
        this.callParent();
    }
});

var kitty = new My.Cat();         // alerts 'Cat', then alerts 'Cat'

var katty = new My.SnowLeopard(); // alerts 'Cat', then alerts 'Snow Leopard'

var cutie = kitty.clone();
alert(Ext.getClassName(cutie));   // alerts 'My.SnowLeopard'
alert(cutie.groupName);           // alerts 'Cat'