View Full Version : very similar component objects

4 Mar 2010, 4:03 AM
I have several identical components in my Ext JS application that create code redundancy.
For example, there are 3 comboboxes for font selection that are exactly alike and implemented through xtype.

Defining one combobox object like this:

var fontCombobox = new Ext.form.ComboBox(
});and using it later:

items: fontComboboxwouldn't work because one and the same object (fontCombobox) would be used in three different places and changing the value in one place (e.g. to "Arial") would also set the other two comboboxes to "Arial".

Another way would be to create one fontoCombobox and then make two copies of it. Then I would have three identical but separate comboboxes.

Is there another, more practical way?

4 Mar 2010, 4:18 AM
Use a factory function:

function createCombo(){
return {
xtype: 'combo'

4 Mar 2010, 5:37 AM
Thanks, your reply led me to this very helpful link: