PDA

View Full Version : Defining A Class Property As Object



rnxfod
9 Jul 2013, 3:13 AM
Am defining several classes in a project am working on but i need to define some of the class member as object of other classes

As in,

in the class below toobar_status is suppose to be a type of another class (also below)
Need assistance to get it right.


Ext.define('App.model.entities.ToolbarMenu', {
menu_id: '',
menu_name: '',
menu_name_id: '',

toolbar_status: App.model.entities.ToolbarStatus,

constructor: function(options) {
Ext.apply(this.options || {});
}
});

Ext.define('App.model.entities.ToolbarStatus', {
is_active_id: '',
is_active_name: '',

constructor: function(options) {
Ext.apply(this.options || {});
}
});

skirtle
9 Jul 2013, 5:14 AM
I see two approaches.

1. Add a requires property to ToolbarMenu and then set toolbar_status in the define callback.

2. Give ToolbarStatus an alias, make toolbar_status a string and look-up the real class at instantiation time.

Given the choice I'd go with the second option but if the property really is a (static) class property then you'd have to go with the first one. If it is a static property it should really be moved into a statics block.