Google News
Backbone Interview Questions
Advantages of Backbone.js :
* You can develop a web application with Backbone.js by using JavaScript with the minimal set of data-structuring (models & collections) and user interface (views & URLs).

* It is best for developing MVC like web applications, single page web applications or complex JavaScript web applications in an organized and structured manner without JavaScript code mixing with HTML.

* It provides API with many functions.

* It provides a key-value binding and custom events.

* It facilitates you to abstract your data into models and your DOM application into views and binds the two together using events.
For multiple page web app in backbone.js there are lots of consideration but here are two which can be useful
Serving the page : In this, where you want to have your web server route everything to the server route everything to serve the same static page. That means that everything in* will serve /var/www/ once the static page is loaded, the JS on that page will decide what to do given the url

Push State : You can still use backbone routing to do your routing, but don’t use hashbangs.  This will allow you to navigate to URLs without actually needing a page refresh.
* To make synchronization process of views and models together, ModelBinder class is used.
* The most powerful capabilities of ModelBinder class is that it enables you to define scope when you create your bindings using jQuery.
* If your views are simple, you can rely on default scoping rules that are based off of the html “name” attribute.

* You can define scoping with jQuery selectors if your views are complex.
The Converter is a function which is used to convert the JavaScript object to a model. It is invoked when the transition is made between an HTML element and the model's attribute.
Sync is a function that is called every time. It attempts to read or save a model to the server. It persists the state of the model to the server.
Two methods can be used to manipulate the Backbone.js utility :
Backbone.noConflict : It returns the Backbone objects to its original value and provides a facility to store the reference to a backbone. It can be used to embed the backbone on third-party websites, where you don't want to thrash the existing backbone.

Backbone.$ : This property is used when you have multiple copies of jQuery on the page or want to tell Backbone to use a particular object as its DOM / Ajax library.
When you want to remove the validation binding on the model or all models , removing all events hooked up on the collection, you can use Unbinding function.
For example : Backbone.Validation.Unbind(view)   [ This will remove the validation binding]
There are the following configuration options available in Backbone.js.
* modelSetOptions
* boundAttributes
* supressThrows
* converter
* change Triggers
* InitialCopyDirection
In Backbone.js, the "id" property on a model is automatically assigned based on the "id" set in the model's attributes hash. This is the ID that we receive from the rest of API for the resource that we are querying. On the other hand, the "cid" is a temporary ID assigned to each model and is useful until an actual ID is assigned for the object.

For example, a model pushed to a collection that has not yet been persisted can be called "cid", until it is saved in the database and an actual ID is generated for it. After that, it can be called "id".
There are mainly two advantages to using "listenTo()" instead of using "on()" to bind event handlers. See the syntax of using these both because they are used differently :
Syntax :
listener.listenTo(object, event, callback)  
object.on(event, callback)  
While using "listenTo()", the object whose events you want to listen to is passed as the first argument. On the other hand, in the case of "on()", it is a method on that object.
The key advantages of "listenTo()" over "on()" are :
* The listener keeps track of all the event handlers, making it easier to remove them all at once when required.
* The callback's context is always set to the listener itself.