PDA

View Full Version : Mixins Documentation more info needed.



webbera
5 Jun 2014, 8:43 AM
Ext.define documentation talks briefly about using mixins like an interface. The problem I have is that mixins only pull in 'functions' and not 'fields'. There is a way around that using the optional onClassCreatedCallback function when defining a class to add the fields from the 'mixin' class. I am just looking for help to learn if there is a better way to 'inherit' multiple classes. Functions and Fields.



Ext.define((String) className, (Object) classMembers, (Optional Function) onClassCreatedCallback);

Phil Guerrant
10 Jun 2014, 8:55 AM
Not quite following... when you use a mixin all of it's "members" are copied onto the destination class. This includes both functions and properties:



Ext.define('Foo', {
bar: 1,
baz: function() {
console.log('baz');
}
});

Ext.define('MyClass', {
mixins: ['Foo']
});

var x = new MyClass();
console.log(x.bar); // 1
console.log(x.baz()); // baz