PDA

View Full Version : best practices question



netnutmike
21 Sep 2011, 1:47 PM
Hi there,

I have been using Extjs 3 for a long time now and am dipping into version 4. I have done some playing and am getting around ok, however, today I downloaded the trial for designer and was playing with it.

Looking at the code it created, I see a much different way of adding items to a window. I have always just used the items: [] in the window definition. But the designer creates it like this:


initComponent: function() {
var me = this;
me.items = [
{
xtype: 'form',
bodyPadding: 10,
dockedItems: [
{

Is there an advantage to using this method vs defining the items in the items definition? This is more of a curiosity as to the recommended method.

Thanks!

Mike

evant
21 Sep 2011, 1:54 PM
Compare these:



Ext.define('A', {
foo: []
});

Ext.define('B', {
constructor: function(){
this.foo = [];
}
});

var a1 = new A(),
a2 = new A(),
b1 = new B(),
b2 = new B();

a1.foo.push('a');
console.log(a2.foo);

b1.foo.push('b');
console.log(b2.foo);

Christiand
22 Sep 2011, 4:20 AM
would not have expected this.

netnutmike
22 Sep 2011, 6:03 AM
That definately makes it clear. That makes it re-usable. Thanks for the clarification.