It seems to me that this should work but I cant see what exactly is the problem.
The error Im receiving is “DDROA is not defined”
Could anyone help enlighten me.
var DDROA = {
AllowedRoutes : {
AR0 : {text : 'SomeText', value : 'SomeValue'},
AR1 : {text : 'SomeText2', value : 'SomeValue2'}
},
RouteContext : {
RC0 : {text : 'None', value : '0',
AllowedRoutes : new Array(
DDROA.AllowedRoutes.AR0 // An error occurs here
)
}
}
}
EDIT
For Slack’s Comment
Can you help explain why I must finish declaring the DDROA.AllowedRoutes and then make another statement to add DDROA.RouteContext in a separate stament. Essentially you are telling me I must
var DDROA = {AllowedRoutes : {}};
then
DDROA.RouteContext = {};
Why the two separate statements. I do things like
var Utilities = {
TextBased : {
someFunction : function(){
//do stuff
},
someFunction2 : function() {
Utilities.TextBased.someFunction();
}
}
};
What is the difference? It seems to me I should get the same error?
Your
DDROAvariable is only assigned after the object is created.Therefore, when the object is initialized,
DDROAisundefined.To work around it, you should set
RouteContextseparately, like this:Also, when given a single argument, theArrayconstructor takes the length of the array.To make an array with a single element, use an array literal, like this
[ DDROA.AllowedRoutes.AR0 ].To answer your edited question, the code inside the function is only executed when the function is called, which is after the variable is assigned.