Im starting to work more and more with Javascript and I occasinally run into the following problem.
I want to assign values, based on values I just entered.
Simple example:
var Example = {
valueA : 100,
valueB : 20,
valueC : Example.valueA / Example.valueB
}
But this gives Example is undefined at the valueC line. I'm assuming that the Example object isn't ready to be used at this point, it first has to "finish being made".
I could do:
var Example = {
valueA : 100,
valueB : 20,
valueC : -1 // Gets value later
}
Example.valueC = Example.valueA / Example.valueB
In this example this would be perfectly accaptable, but I end up in situations where I would have a lot of these "post init" problems, or the assigned values are a bit more complecated (eg a formulae).
Can something like "Simple Example" work? My Current solution feels like overkill, I need something more elegant which reads better when reading the code.