PDA

View Full Version : What are differences between "override", "extend" and "mixins"?



16 Oct 2013, 1:45 PM
Hi!

Ext.define ... override, extend, mixins

I am confused about the differences between "override", "extend" and "mixins".

When should I use "override", "extend" or "mixins"?

Thank you for your answers!!!

16 Oct 2013, 1:56 PM
I found the definitions about that.
The "extend" doesn't override existed properties, but "override" is overriding existed properties. The "mixins" is just copy the properties of the existed object to the new object.

extend: =>
for (var m in o) {
if (!o.hasOwnProperty(m)) {
continue;
}
this[m] = o[m];
}
override:=>
if (cls.prototype.$className) {
return cls.override(overrides);
}
else {
Ext.apply(cls.prototype, overrides);
}
mixins?=>
mixin: function(name, cls) {
var mixin = cls.prototype,
my = this.prototype,
key, fn;


for (key in mixin) {
if (mixin.hasOwnProperty(key)) {
if (typeof my[key] === 'undefined' && key !== 'mixins' && key !== 'mixinId') {
if (typeof mixin[key] === 'function') {
fn = mixin[key];


if (typeof fn.$owner === 'undefined') {
this.ownMethod(key, fn);
}
else {
my[key] = fn;
}
}
else {
my[key] = mixin[key];
}
}

else if (key === 'config' && my.config && mixin.config) {
Ext.Object.merge(my.config, mixin.config);
}

}
}


if (typeof mixin.onClassMixedIn !== 'undefined') {
mixin.onClassMixedIn.call(cls, this);
}


if (!my.hasOwnProperty('mixins')) {
if ('mixins' in my) {
my.mixins = Ext.Object.merge({}, my.mixins);
}
else {
my.mixins = {};
}
}


my.mixins[name] = mixin;
},