I am building an application in Angular, so any Angular answers are acceptable, however my question is about JavaScript in general.
My application used several JSON files to store information. These JSON files are loaded into tags headwith tags script, and the objects inside them are assigned to variables in the service. There are three main JSON objects I work with, and some of them are dependent on others.
For example, one of them has an attribute Descriptionthat includes the text in conjunction with the expression, for example The value is {{10+(2*var)}}.
However, one of the other objects has children, some of which may or may not be included at the time of compilation Description. One child has a value that will be stored as var2, and the other does not.
If I changed my expression to:, The value is {{(10+(2*var))*var2}}then the value will be valid only if the first child is used and defines var2. If a second child is used, var2not determined, and as a result leave me with "NaN".
The best way I can think of is to make another object that contains all the possible values from the child children, and set them to default, and then override them when there is a child with a value.
However, this has several disadvantages. First, I have to have all the variables (there are many) present in another object when most of them are not needed. I will also have to "reset" this object again.
Is there a more efficient, more standardized way to solve this kind of thing?