[Answered ]-Simple explanation of how BackboneJS works?

2πŸ‘

1. What is the first function/object created/called by BackboneJS ( entry point )?

Backbone.js follows MVC architecture. Model defines the actual structural design of model. View defines how the application visually displayed. This view will create the instance of Model and it will be used in the application.
So, in backbone application, Instance of view is created first. When we create an instance of View by calling new myView();, initialize() function will be called first. Model can be instantiated from View as per the requirements.

2. What is the first function/object created/called by BackboneJS ( entry point )?
 When you create the instance of model, you can provide the data through that instance. There are getters and setters available for Model.
For example, User is the Model for above JSON. Model is instantiated as below.

var user=new User({β€œid”:”1”,””name”:”john”,”age”:20,”gender”:”male”});

You need to access the JSON object to define the model.

3.How does backboneJS model map to the individual fields in the JSON data (id, name, age)?
As said before, individual fields can be mapped while instantiating or with the getter and setters of backbone.js

4.How can i peep in the collections/models created by backboneJS using browser javascript console?
You can console the java script objects with toJSON() function. Usually, underscore.js provides more utility functions in backbone.js.

You need to browse through backbone.js documentations.

πŸ‘€Umesh Patil

0πŸ‘

Addy Osmani did a fine job of explaining that and going even bit more into details down here -> https://github.com/addyosmani/backbone-fundamentals

πŸ‘€Tom Tu

Leave a comment