I am trying to create some objects to store information on how to map an incoming object (from json) to a specific representation, and I use code that looks something like the following:
LocationMap = {
fields: {
"name": ValueMap(),
//"parentLocation": ModelMap(LocationMap),
}
}
PersonMap = {
fields: {
"name": ValueMap(),
"location": ModelMap(LocationMap),
}
}
The MapValue and MapModel functions can be thought of as returning functions which act on the incoming value to map it to a new value.
The trouble I'm having is with the commented out line, where I need the Location object to recursively reference itself, which is of course impossible. If these were classes in another language I think there could be a recursive reference. How can I accomplish the same thing with JavaScript?
I made a small working example on jsfiddle.