Ext Objects inheritance
by Johan Vandeplas
JavaScript
Ext.onReady(function () {
Ext.define('CanSneeze', {
sneeze: function(){
console.log(this.name + ' sneezed');
},
showYourLegs: function () {
console.log("I am " + this.name + " and I'm cool but how many legs to I got?");
}
});
Ext.define('Animal', {
name: 'noName',
legs: 4,
age: 0,
showYourLegs: function () {
console.log('I have ' + this.legs + ' legs');
}
});
Ext.override(Animal, {
/* showYourLegs: function () {
console.log('I am ' + this.name + ' an I have ' + this.legs + ' legs.');
}, */
showYourName: function () {
console.log('I am ' + this.name);
}
});
Ext.define('Dog', {
extend: 'Animal',
mixins: {
canSneeze: 'CanSneeze'
},
name: 'someName',
legs: 4,
age: 0,
bark: function () {
console.log('I Say BARK!');
},
showYourLegs: function(){
this.mixins.canSneeze.showYourLegs.apply(this, arguments);
this.callParent(arguments);
}
});
Ext.define('Duck', {
extend: 'Animal',
constructor: function(config){
var me = this;
Ext.apply(me, config);
me.callParent(arguments);
},
name: 'someName',
legs: 2,
age: 0,
kwak: function () {
console.log('I Say KWAK!');
}
});
var dog = Ext.create('Dog', {
name: 'Labrador',
age: 5
});
var duck = Ext.create('Duck', {
name: 'Donnald',
age: 3
});
dog.showYourLegs();
dog.showYourName();
dog.bark();
dog.sneeze();
console.log(dog);
duck.showYourLegs();
duck.showYourName();
duck.kwak();
});