PDA

View Full Version : Advice on handling default configs in Ext?



haibijon
16 Mar 2007, 11:23 AM
I was wondering if anyone had any suggestions/advice on handling default options in ext. My current code looks like the following, any advice better way to do this using Ext?



var Component = function( id, config ){

// apply default config
this.someOptions = ['foo','bar'];
this.anotherOption = 42;

// apply passed config to override defaults
Ext.apply(this, config);
};

var x = new Component( 'someId', {
someOptions: ['x', 'y']
} );

Animal
16 Mar 2007, 11:41 AM
Set defaults on the prototype. See for example: http://www.yui-ext.com/deploy/ext-1.0-alpha3/source/widgets/menu/Menu.js

eg



var Component = function( id, config ){
// apply passed config to override defaults
Ext.apply(this, config);
};

Component.prototype = {
someOptions: ['foo','bar'],
anotherOption: 42
};

var x = new Component( 'someId', {
someOptions: ['x', 'y']
} );

haibijon
16 Mar 2007, 11:43 AM
Gotcha, much cleaner. Thanks for the help!