Ext Core 4 Class Example

    Ext.require('Sample.Person', function() {
        var aaron = new Sample.Person({
            name: 'Aaron Conran',
            gender: 'male',
            isCool: true
        });

        alert(aaron.getName()); // 'Aaron Conran'
        alert(aaron.getGender()); // 'male'
        alert(aaron.getIsCool()); // true

        aaron.eat("Salad"); // alerts "I'm eating: Salad"

        aaron.setGender('weird');
        alert(aaron.getGender()); // 'unknown'
    });

    Ext.require('Sample.Developer', function() {
        var tommy = new Sample.Developer({
            name: 'Tommy Maintz',
            languages: ['PHP', 'JavaScript', 'HTML', 'CSS']
        });

        tommy.code('Objective-C'); // alerts "I can't code in: Objective-C"
        tommy.code('JavaScript'); // alerts "I'm coding in: JavaScript"
                                  // alerts "I'm eating: Bugs"
    });

    Ext.require('Sample.Musician', function() {
        var dave = new Sample.Musician({
            name: 'David Kaneda',
            isCool: true
        });

        dave.composeSongs(); // alerts "David Kaneda is composing songs"
        dave.playGuitar(); // alerts "David Kaneda is playing guitar"

        var anotherDave = Sample.Musician.clone(dave);
        alert(anotherDave.getName()); // alerts "David Kaneda"
    });

    Ext.require('Sample.CoolGuy', function() {
        var jacky = new Sample.CoolGuy({
            name: 'Jacky Nguyen',
            isCool: true
        });

        jacky.playGuitar(); // alerts "Jacky Nguyen is playing guitar"
        jacky.sing("Love Me or Die"); // alerts "Ahem..."
                                      // alerts "I'm singing: Love Me or Die"
    });

    Ext.require(['Sample.Developer', 'Sample.HumanResource'], function() {
        var jacky = new Sample.Developer({
                name: 'Jacky Nguyen',
                languages: ['PHP', 'JavaScript', 'HTML', 'CSS']
            }),
            noobie = new Sample.Developer({
                name: 'Noobie Dumb',
                languages: ['LameScript']
            }),
            hr = Sample.HumanResource;

        hr.recruit(noobie); // alerts "Noobie Dumb doesn't know JavaScript, no point recruiting!"
        hr.recruit(jacky);

        alert(hr.getDevelopersCount()); // alerts 1
    });

    Ext.require(['Sample.deadlock.A'], function() {
        // should throw Error
    });

    Ext.require(['Sample.notdeadlock.A'], function() {
        alert("Loading sequence: " + Ext.Loader.history.join(" -> "));
    });

    Ext.require(['Sample.CTO', 'Sample.Developer'], function() {
        var abe = new Sample.CTO();
        alert(abe.isGeek); // alerts true
        alert(abe.isSuperGeek); // alerts true
        alert(abe.getAverageIQ()); // alerts 140
                                   // not the current class

        var ape = abe.clone();
        alert(Ext.getClassName(ape)); // alerts 'Sample.CTO'

        var jacky = new Sample.Developer();
        alert(jacky.getAverageIQ()); // alerts 120

        var jackie = abe.hireNewDeveloperLike(jacky);
        alert(Ext.getClassName(jackie)); // alerts 'Sample.Developer'
    });

    Ext.define('My.own.A', {
        statics: {
            myName: 'A'
        },

        constructor: function() {
            alert(this.statics().myName);
            alert(this.self.myName);
        },

        clone: function() {
            var cloned = new this.self();

            cloned.rootName = this.statics().myName;

            return cloned;
        }
    });

    Ext.define('My.own.B', {
        extend: 'My.own.A',

        statics: {
            myName: 'B'
        },

        clone: function() {
            var cloned = this.callParent();

            cloned.special = true;

            return cloned;
        }
    });

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

    var aa = a.clone();
    var bb = b.clone();

    alert(Ext.getClassName(aa)); // alerts 'My.own.A'
    alert(Ext.getClassName(bb)); // alerts 'My.own.B'

    alert(aa.rootName); // alerts 'A'
    alert(bb.rootName); // alerts 'A'
    alert(bb.special); // alerts true

    Ext.define('My.Cat', {
        statics: {
            totalCreated: 0,
            speciesName: 'Cat' // My.Cat.speciesName = 'Cat'
        },

        constructor: function() {
            var statics = this.statics();

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

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

            statics.totalCreated++;

            return this;
        },

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

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

            return cloned;
        }
    });

    Ext.define('My.SnowLeopard', {
        extend: 'My.Cat',

        statics: {
            speciesName: 'Snow Leopard'     // My.SnowLeopard.speciesName = 'Snow Leopard'
        },

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

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

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

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

    alert(My.Cat.totalCreated);             // alerts 3

    Ext.define('Bank', {
        money: '$$$',
        printMoney: function() {
            alert('$$$$$$$');
        }
    });

    Ext.define('Thief', {});

    Thief.borrow(Bank, ['money', 'printMoney']);

    var jacky = new Thief();

    alert(jacky.money); // alerts '$$$'
    jacky.printMoney(); // alerts '$$$$$$$'