I am creating front-end of a web app. I am receiving all the responses in JSON, parsing it and putting it as html. I had a look at few javascript MVC frameworks (i.e backbone.js, ember.js etc) and found that they were just overkill for my simple app. But what I found really fascinating is that they all had Models. I figured out I can create javascript objects and they will be similar to models and as I dont have such complex needs my custom javascript objects shall be easy to make.
function displayCar() {
var result = "A Beautiful " + this.year + " " + this.make
+ " " + this.model;
pretty_print(result);
}
function Car(make, model, year, owner) {
this.make = make;
this.model = model;
this.year = year;
this.owner = owner;
this.displayCar = displayCar;
}
I receive the cars as JSON response from the server. SO what would be the ideal way : To create the objects while looping over the JSON array OR should I just use the parsing and directly show html from there?
Now my question is should I parse the JSON into javascript objects? I am also not sure if using this kind of objects would be much helpful? I would also like to know if there is a way to create custom pre-defined objects straight from JSON, as I feel than it might be useful like I want to car objects
JSON.parse()on modern browsers).