![]() |
VOOZH | about |
What is Backbone.js?
It is a lightweight library for structuring JavaScript code. It is also regarded as the MVC/MV* kind of framework. If you are not familiar with MVC, it is basically an architecture pattern for implementing user interfaces. It separates the application into three kinds of components:
The intention is to promote separation of concerns which results in better structured and more maintainable application. Backbone.js does provide the concept of model and views but Backbone.js views are like controllers in MVC. So it's more way of the MV* kind of framework. And to be more accurate it is not even a framework it is just a library that you can use anywhere you want.
Backbone.js also provides the concept called a router. It is used for developing single-page applications. A single-page application is a kind of web application that fits on a single web page. Aiming to provide a rich user experience similar to desktop applications.
In a single-page application, all the necessary code such as HTML, CSS, and JavaScript is retrieved with a single page load. It provides the following features:
With Backbone.js we can create a single-page application. Backbone works perfectly in building a rich-client application over a set of REST APIs.
Features of Backbone.js: There are the following advantages of Backbone.js:
Installation process: You can use Backbone.js with the following methods:
Downloading from the official website: Open the http://backbonejs.org/ and there you will find three options as shown below:
Using the CDN Link: A content delivery network is a network that serves files to users. Here are the CDNs for Backbone.js
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js" type="text/javascript"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script>
Example:
Output:
In this case, we are using Backbone.js and we have used CDNs for this. Here we are creating a model named Company. And we have created an instance of a model Company which is a company. We have set two attributes to it:
We can set attributes using a set keyword with an instance of the model created. And printing it on the document using a model.get( ) method. So we will get output as:
Company name is: GFG and category is: Education
Major components of Backbone.js: The major components of Backbone.js are:
Application of Backbone.js: There are the following application of Backbone.js
Advantages of Backbone.js: There are the following advantages of Backbone.js:
Disadvantages of Backbone.js: It requires a longer development time