-
17 Oct 2012 12:14 PM #1
Ext.util.Observable usage
Ext.util.Observable usage
I did a search of the entire Ext JS code base to see how the Ext.util.Observable class is used...
The mixin pattern is used the most frequently, but a small number of Ext JS classes extend Observable.
Is there a reason for this inconsistency? I think the mixin pattern should be preferred because it makes the prototype chain shorter.
Code:Ext.define('Ext.state.Provider', { mixins: { observable: 'Ext.util.Observable' }, ...Code:Ext.define('Ext.selection.Model', { extend: 'Ext.util.Observable', alternateClassName: 'Ext.AbstractSelectionModel', requires: ['Ext.data.StoreManager'], mixins: { bindable: 'Ext.util.Bindable' }, ....
-
19 Oct 2012 9:49 AM #2
I can't speak authoritatively (of course), but if I were to offer a guess, my first impression is that it could be because Ext.util.Observable provides a constructor that is automatically inherited by subclasses, but has to be explicitly called when used as a mixin. As a result, strict subclasses have somewhat cleaner code:
Whether the shorter prototype chain is worth the tradeoff with more verbose code is a separate question, I think. And this is just a guess anyway.Code:Ext.define('MixinObservable', { mixins: { observable: 'Ext.util.Observable' }, constructor: function() { var me = this; me.mixins.observable.constructor.call(me); } }) // ... versus ... Ext.define('SubclassObservable', { extend: 'Ext.util.Observable' });


Reply With Quote