PDA

View Full Version : Mixin to override constructor & callParent?



da_b0uncer
8 Apr 2013, 11:06 PM
Do mixins enable me to "transparently" override a constructor?


Ext.define('MyMixin', {
constructor: function(config) {
//...modify config
this.callParent( [config] );
}
});

Ext.define('MyClassA', {
extends: 'Ext.some.sort.of.Class',
mixins:['MyMixin']
});

Ext.define('MyClassB', {
extends: 'Ext.some.different.sort.of.Class',
mixins:['MyMixin']
});

Or would I have to get a list of classes and run a override loop on it?

slemmon
10 Apr 2013, 12:02 PM
Mixins won't step on the members of the classes they're added to if the member is already defined. I don't believe there's a way to do what you're hoping - you'd need to override the classes explicitly.

da_b0uncer
10 Apr 2013, 12:50 PM
yes, I had to make a loop over all classes, which needed the new constructor, pretty ugly, but probably the only way. :\

slemmon
10 Apr 2013, 1:02 PM
I tried to come up with a more elegant solution, but I think that IS the most elegant solution to date.