PDA

View Full Version : Is this the correct way to define new class?



extremed
13 Jan 2012, 7:02 AM
Hi

Im trying to extend panel so is this the correct way to do this?



Ext4.define('Ext4.ux.NewPanel', {
extend : 'Ext4.Panel',
alias : 'widget.newpanel',
config: {
hidden : true,
autoRender : true,
floating : true
},
items: [
......
],
constructor: function(config) {
this.initConfig(config);
this.callParent(arguments);
return this;
}


Regards

hendricd
13 Jan 2012, 7:20 AM
@extremed --


No need to return 'this' in the constructor.
config support in 4.0.x is only partially implemented (4.1 has improved support).
NEVER define complex objects (items : [], tbar, buttons, dockedItems, etc ) in the class prototype, declare them in the constructor or initComponent template methods.

Review requires and/or uses declarations in the documentation as your class' capabilities evolve.

Otherwise, looks good. ;)

extremed
13 Jan 2012, 7:47 AM
Thanks.

Any examples on how to declare Items in the constructor or initComponent template methods?


Regards

hendricd
13 Jan 2012, 8:08 AM
Thanks.

Any examples on how to declare Items in the constructor or initComponent template methods?


Regards

Via the constructor:



constructor: function(config) {
config = config || {};
Ext.apply(config, {
items : [ ..... ],
dockedItems : [..],
tbar : [ ]
});
this.initConfig(config);
this.callParent([config]);

},.....


OR, via initComponent


initComponent : function(){

Ext.apply(this, {
items : [ ..... ],
dockedItems : [..],
tbar : [ ]
});
this.callParent();
},....

extremed
13 Jan 2012, 8:18 AM
Thanks a lot :)

slemmon
13 Jan 2012, 9:10 AM
Is there a resource (learn doc, forum post, etc.) that goes over all of the ins and outs of constructor -vs- initConfig -vs- initComonent in the 4.x environment?

Not only for components, but other classes like stores, readers, base utils, etc.?