I have a "singleton" class in Javascript declared like the following:
ExpressionValidator =
{
// A map of function names to the enumerated values that can be passed to it.
functionParamValues:
{
"Func1": ["value1", "value2", "value3"],
"Func2": ["value1", "value2", "value3"]
}
}
I would like to somehow define the array of ["value1", "value2", "value3"]
in such a way that it doesn't have to be copy-pastaed everywhere that it is needed, but I cannot figure out how to make it work.
My current idea looks something like this:
ExpressionValidator =
{
// An array of possible values to use as parameters to certain functions.
values:
[
"value1",
"value2",
"value3"
],
// A map of function names to the enumerated values that can be passed to it.
functionParamValues:
{
"Func1": values
"Func2": values
}
}
But this doesn't work because it can't find the values
array when trying to initialize the "Func1" and "Func2" properties of the functionParamValues
object. I also tried using this.values
instead of just values
but it ends up as null
so I assume it's trying to get the values
property of the functionParamValues
object, not the parent ExpressionValidator
.
I know this can be solved by moving the values
array outside of the ExpressionValidator
definition, but I would like to keep it inside if possible so that it doesn't conflict with anything in the global namespace. This should only be a last resort if there's really no other way to do it.