19 March 2012
Basic understanding of JavaScript.
Sample files:
All
One of the challenges when building nontrivial web applications is that JavaScript’s non-directive nature can initially lead to a lack of structure in your code, or in other words, a lack of… backbone. JavaScript is often written as a litany of free-hanging and unrelated blocks of code, and it doesn’t take long before it becomes hard to make sense of the logic and organization of your own code.
Backbone.js is a lightweight framework that addresses this issue by adding structure to JavaScript-heavy web applications.
Backbone.js provides several classes (Model, Collection, View, Router) that you can extend to define the building blocks of your application. To build an application with Backbone.js, you first create the Models, Collections, and Views of your application. You then bring these components to life by defining a “Router” that provides the entry points of your application through a set of (deep-linkable) URLs.
With Backbone.js, you can organize your code in self-contained entities (Models, Collections, Views), in short—no more free-hanging and unrelated blocks of code.
With Backbone.js, you bind Views to Models so that when a Model’s data changes, all the Views bound to that Model automatically re-render. There is no more need for complex UI synchronization code.
Backbone.js also provides a natural, magical, and elegant integration with RESTful services. If you expose your back-end data through a pure RESTful API, the operations of retrieving (GET), creating (POST), updating (PUT), and deleting (DELETE) models are incredibly easy using the Backbone.js simple Model API.
In this three-part tutorial, you’ll create a Wine Cellar application that allows users to browse through a list of wines, as well as add, update, and delete wines.
To see a working version of Part 1, the read-only version of the application, click here.
The code for backbone.js is as follows. I suggest that you download the code from my source control site to follow along. The link for this application is in the Requirements section of this tutorial.
Next, read Part 2: CRUD, so that you can learn how to add more functionality to this application.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.