From couple of days, I have started working/learning the backbone.js. I have read documentation on their site. I have also read few tutorials available here.
As per my understanding below are few major differences between Views and Models.
- Only view has ‘el’. Why it is not there in Model ?
- Only Models have ‘get’,’set’, ‘save’ methods.
- Only Models have functions like fetch, save, destroy, validate
methods,clear,has.
According Hello World examples here, View can also do the things Models can do.
- Both have extend, render, initializer, getter setter methods.
- Both can be converted into JSON using toJSON.
hence, I am confused between Models and Views. When to use each one ?
my question is.. what is practical difference between Models and Views? What are different situations to use Models/Views ? What should be appropriate to use for displaying(render)?
Can anyone good @ Backbone.js explain with practical scenario ?
Your help will make my understanding much clear.
Model and Views are not Backbone terms. You can read about MVC paradigm first.
Model contain data and logic for data manipulations. View describes how this data should be displayed.
Hence only View have ‘el’ – because this it is used while displaying data.
Getters and setters are in model according to MVC paradigm.