I understand that JSON is for exchanging information. What's confusing me is, I would like to be able to use JSON for storing and calling Objects and their constructors if possible, but since JSON is literal notation I was wondering if there was a way to fill in the JSON object parameters with some type of constructor much like the way a normal constructor would work.
The closest thing I've found is this:
Normal Constructor:
var dude = function(name, age) {
this.name = name;
this.age = age;
}
var bro = new dude("chad", 22);
JSON:
var bro = {
'name': "chad",
'age': 22
};
But even these aren't really the same considering with the constructor you can call var bro2 = new dude("tony", 21);
at any time and have a new instance of dude
whenever you want. How could you keep this type of functionality with JSON thrown into the mix?