Cross-reference js-object variables when creating object

Posted by Ivar Bonsaksen on Stack Overflow See other posts from Stack Overflow or by Ivar Bonsaksen
Published on 2010-06-14T11:57:40Z Indexed on 2010/06/14 12:02 UTC
Read the original article Hit count: 267

Filed under:
|
|

Summary:

I want to know if it is possible to do something like this:

{a: 'A',b: this.a}

...by using some other pointer like {a: 'A',b: self.a} or {a: 'A',b: own.a} or anything else...

Full question:

I'm trying to extend MyBaseModule using Ext.extend, and need to cross-reference values in the extension object passed to Ext.extend().

Since I'm not yet in context of MyModule, I'm not able to use this to reference the object (See example below line 12). Is there any other way to reference values like this without creating the object first?

1 MyModule = Ext.extend(MyBaseModule, {
2   dataStores: {
3       myDataStore: new Ext.data.Store({...})
4   },
5
6   myGridDefinition: {
7       id:                 'myGridDefinitionPanel',
8       bodyBorder:         false,
9       items: [{
10          xtype:          'grid',
11          id:             'myGridDefinitionGrid',
12          store:          this.dataStores.myDataStore
13      }]
14  }
15 });

Or is the following the only solution? I would like to avoid this if possible, as I find it less readable for large extension definitions.

1 var extensionObject = {
2   dataStores: {
3       myDataStore: new Ext.data.Store({...})
4   },
5
6   myGridDefinition: {
7       id:                 'myGridDefinitionPanel',
8       bodyBorder:         false,
9       items: [{
10          xtype:          'grid',
11          id:             'myGridDefinitionGrid'
12      }]
13  }
14 };
15
16 extensionObject.locationsGrid.items[0].store = extensionObject.dataStores.locations;
17
18 MyModule = Ext.extend(MyBaseModule, extensionObject);

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about extjs