I just need a simple lesson in objects and constructors.
var mapMarkers = {
key: null,
contactName: null,
location: null,
};
var markersArray = Object.keys(mapMarkers);
class Map extends Component {
renderMarker = ({ key, contactName, location }) => {
newMarker = new mapMarkers(key, contactName, location);
}
Recurring theme for me, there is no information online for how to do this. I need an actual working example to be able to follow, theory is useless.
What I am trying to do is define an object type called mapMarkers with its own attributes. Then I would like to dynamically be able to create instances of this object and populate them into an array.
The end goal for this is to try and use this array to populate my map with markers. The error I am getting is that:
newMarker = new mapMarkers(key, contactName, location);
is not a valid constructor, according to the compiler. So I want to know what a valid constructor for this would look like, as the information online tell me nothing.
Also, what does:
var markersArray = Object.keys(mapMarkers);
actually do? Does keys mean that when I instantiate an object it automatically populates this array? Or do I need an additional step to do this?
Thanks guys.
Edit: The suggested answer is not relevant to me at all, the language does not appear to be the same and I cannot see a working example in there anywhere that I can compile and run. They are also not trying to do the same things as described here.