Is there a way to attach a mixin to a class after it has been created (or inside its constructor from options)?
Printable View
Is there a way to attach a mixin to a class after it has been created (or inside its constructor from options)?
Yes, you can technically but we recommend that you have it at class creation and then you can execute methods on that mixin later on.
You certainly could if absolutely needed using the static 'mixin' method that exists in every class. For example:
Note that this is currently a private API, hence it's still subject to change.Code:Ext.define('A', {
foo: true
});
Ext.define('B', {
bar: true
});
A.mixin('b', B);
Hum, seems to fit my needs but i can't make it work :
Code:Ext.define('Ext.i18n.Locale', {
extend: 'Ext.Base',
mixins: ['Ext.util.Observable'],
constructor: function(config) {
// Merge defaults
this.config = Ext.Object.merge(this.config, config);
// Load mixins
_.each(this.config.mixins, function(value, key) { Ext.i18n.Locale.mixin(value, Ext.ClassManager.get(value)); });