This is normal. To understand, you should follow the following rules when defining a class:
- Extending class will be done before mixing classes: During extending, members form parent class will be attached to class prototype.
- During mixing classes, members from mixins classes only be attached to class prototype if it does not exists yet.
Follow these rules, let try to walk thru the code:
Code:
Ext.define('CanSing', {
sing: function(b) {
console.log('CanSing.sing')
console.log("I'm on the highway to hell...", b);
this.sang();
},
sang: function(b) {
console.log('CanSing.sang')
console.log("I'm on the highway to hell...", b);
}
});
CanSing.prototype will contain sing() and sang() methods.
Code:
Ext.define('CanSing2', {
extend:'CanSing',
sang: function(b) {
console.log('CanSing2.sang')
console.log("2", b);
}
});
CanSing2.prototype will contain:
- sing() method from extending CanSing class.
- sang() method form CanSing2 definition.
Code:
Ext.define('Musician', {
mixins: {
foo: 'CanSing'
},
sing: function(b) {
console.log('Musician.sing')
this.mixins.foo.sing.call(this);
}
});
Musician prototype will contain:
- sing() from Musician definition.
- sang() from mixing CanSing class.
Code:
Ext.define('Musician2', {
extend:'Musician',
mixins: {
foo: 'CanSing2'
}
});
Musician2 prototype will contain:
- sing() method from extending Musician.
- sang() method from extending Musician which is from CanSing.
sang() from mixing CanSing2 will not be attached to Musician2 prototype.