custom events

by ATechieDiary

HTML

<link rel="stylesheet" href="http://extjs.cachefly.net/ext-4.0.2a/resources/css/ext-all.css">

JavaScript

Ext.define('Employee', {
    extend: 'Ext.util.Observable',
    constructor: function (config) {
        this.name = config.name;
        this.addEvents(
            "sayHello",
            "sayGoodbye");
        this.listeners = config.listeners;
        this.callParent(arguments);
    },
    listeners: {
        sayHello: function () {
            alert(this.name + " says Hello in parent!");
        },
        sayGoodbye: function () {
            console.log(this.name + " says goodbye!");
        }

    }
});

var newEmployee = new Employee({
    name: "Neil",
    listeners: {
        sayHello: function () {
            alert(this.name + "Overriding says Hello!");
        },
        sayGoodbye: function () {
            alert(this.name + "Overriding says goodbye!");
        },
        sayNothing: function () {
            alert(this.name + " says Nothing !!!");
        }
    }
});

newEmployee.fireEvent('sayHello');
newEmployee.fireEvent('sayGoodbye');