View Full Version : constructors that check config when they should check "this"?

29 Jun 2011, 9:31 AM
I'm trying to abstract and compartmentalize some code, and I ran into some annoying differences between specifying a property via config versus as an object property on a subclass. I logged a bug about it here (http://www.sencha.com/forum/showthread.php?138830-Ext.data.AbstractStore-forces-model-to-always-come-from-config&p=620380#post620380), but I wanted to talk about the question in general.

Do you run into this a lot? I did some searches through other code, and I found more examples:

Ext.data.Association = Ext.extend(Object, {
primaryKey: 'id',

constructor: function(config) {
Ext.apply(this, config);

var types = Ext.ModelMgr.types,
ownerName = config.ownerModel,
associatedName = config.associatedModel,
ownerModel = types[ownerName],
associatedModel = types[associatedName],

Ext.data.Store = Ext.extend(Ext.data.AbstractStore, {
constructor: function(config) {
config = config || {};

* The MixedCollection that holds this store's local cache of records
* @property data
* @type Ext.util.MixedCollection
this.data = new Ext.util.MixedCollection(false, function(record) {
return record.internalId;

Ext.data.TreeStore = Ext.extend(Ext.data.AbstractStore, {
constructor: function(config) {
config = config || {};
var rootCfg = config.root || {};
rootCfg.id = rootCfg.id || this.defaultRootId;

Ext.data.RecordNode = Ext.extend(Ext.data.Node, {
constructor: function(config) {
config = config || {};
if (config.record) {
// provide back reference
config.record.node = this;

The list goes on an on. It's really an impediment to making your own subclasses as sometimes you can just define certain settings as object properties, but other times you have to make your own constructor and put them in a config object.