Frequently Asked Backbone.js Interview Questions Part – 2
Explain What Is Backbone.js?
Backbone.js is a JavaScript client-side (front end) framework, which helps to organize your code and makes it easier to develop single page applications. It allows you to structure JavaScript code in an MVC (Model, View , Controller) fashion.
Model:
It is a part of your code that populates and retrieves the data.
View:
It is the HTML representation of this model.
Controller:
It enables you to save your javascript application via a hashbang URl.
What Are The Main Components Of Backbone.js ?
The main component of Backbone.js are:
Model
View
Collection
Router
Event class object
Explain What Is Backbone.js Collections?
An ordered set of models are represented by Backbone.js collections. Any event in model will trigger an event in collection directly. For example, you can bind “change” event to be notified in a case when any model in the collection has been modified.
Explain What Is Backbone.js Router Is Used For?
When ever an application want to change their URL fragment in order to provide bookmarkable and shareable URLs for an Ajax heavy application, backbone.js router is used.
What Is Backbone Events?
Backbone events is a module that can be mixed in to any object, giving the object the ability to bind and trigger custom named events. Events are not declared before they are bound to any object . Events reflects the state of the model.
What Are The Keypoints Of Backbone?
It has hard dependency with underscore.js to make it more functional and supporting a range of useful collection based operations With jQuery it has a soft dependency
When the model changes it can update the HTML of your application automatically
It uses client-side rendering framework or Javascript templating to render html which avoid you to embed HTML code inside JavaScript code.
For UI updates and DOM manipulations if offers a significantly clean and elegant way.
Why You Have To Use Backbone ? Advantages?
By using JavaScript with the minimal set of data-structuring ( models & collections) and user interface (views & URLs) it enables you to develop a web application
Backbone is best useful to develop 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
Provides key value binding and custom events
API with tons of functions
Robust event handling
API connetion over a RESTful JSON interface
What Are The Three Js Files That You Require To Setup A Working Environment For Backbone?
you are required following three js files to setup a working environment for backbone
jQuery
Backbone
Underscore
In your application put these files within js folder and use it in your index.html page
Explain When You Require Backbone.js?
Backbone.js is required in following condition:
When developing a web application that requires a lot of JavaScript
It is required when you want to give structure to your code, if your application needs to be scalable.
Backbone is useful when a web application has to work with jQuery to traverse the DOM or give animations.
Explain What Is View In Backbone.js?
Backbone view is a Javascript object that manages a specific DOM element and descendants.
Views are not HTML
It is a description of a model
The HTML code comes from templates
Works with any template system
Explain What Is Backbone.js Models?
Backbone.js models are object and core of backbone.js. It contains an array of attributes and listens for events. To represent your data, Backbone provides a model object. For example, you have a to do list, you would have a model representing each item on that list.
Explain How You Can Use Backbone.js For Multiple Page Web App?
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 http://wisdomjobs.com/* will serve /var/www/wisdomjobs.com/index.html. 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.
Explain What Is Modelbinder In Backbone.js ?
To make synchronization process of views and models together, ModelBinder class is used.
What Is The Most Powerful Capabilities Of The Modelbinder ?
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.
Explain What Is Converter In Backbone.js?
A function is called when model’s attribute is copied to an html element or when an html element value is copied into a model’s attribute, this function is referred as Converter in Backbone.js
What Is Model.attributes?
The attributes property is the internal hash containing the model’s state, usually a form of the JSON object representing the model data on the server. It is often a straightforward serialization of a row from the database.
What Is The Function Of Tojson?
It returns a shallow copy of the model’s attribute for JSON stringification. This function is used for persistence, serialization and for augmentation before being sent to the server. This does not return a JSON string.
Explain When You Can Use Unbinding Function In Backbone.js?
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]
What Are The Configuration Options Available?
The configuration options available are:
InitialCopyDirection
modelSetOptions
change Triggers
boundAttribute
suppressThrows
converter
Mention What Are The Typical Problems You Might Face With The Backbone View Code?
Application models don’t change very often
Application pages are frequently refreshed from scratch from the server
Between different view models are not shared
What Is The Function Of Escape?
It gets the current value of an attribute from the model but returns the HTML-escaped version of a model’s attribute. It is helpful in preventing XSS attacks, if you are interpolating data from the model into HTML.
Explain What Is The Function Of Parse?
When ever a model’s data is returned by the server, in fetch and save , this data is called parse. It is called by Backbone whenever a collection’s models are returned by server, in fetch.
What Is Backbone.sync Is Used For?
When Backbone wants to save or read a model to the server it calls out a function called as Backbone.sync.
In Backbone View, What Is The Use Of Setelement?
setElement function is used when Backbone view has to be applied to a different DOM element.