Backbone.js provides you with extremely simple ways to create models and views which organize your code in a logical way that separates the code that creates the interface that the user sees and interacts with (the view) from the data and processing of that data (the model). This separation allows you to be able to switch models and/or views without requiring changes to the other. So you can use the same model with other views or change the way the model stores data without requiring any changes in the view.
You may have noticed that I haven’t mentioned anything about controllers. This is because Backbone.js isn’t a true MVC framework and lacks controllers, but has routers for a similar purpose. This isn’t really a fault. A controller tends to be most useful for client-server relationships because the controllers on the server intercept the requests from the view on the client machine and dictate the actions that should be done, but when everything is run in the client, the view can communicate directly with the model.
Backbone.js automatically utilizes the observer pattern on its models, so the views can directly listen to any changes that happen to a model (such as a value changing) and immediately update the view to reflect those changes. Backbone.js also comes with built in support for jQuery and Zepto for DOM manipulation. Another bit of the library that can come in handy is their collections, “with a rich API of enumerable functions,” which contain multiple models for simpler maintenance, rather than your view needing to worry about multiple models itself. Finally, Backbone connects everything to your existing back-end API through a RESTful JSON interface, and can even synchronize with back ends that don’t support REST and JSON, though it takes a little tweaking.
I’ve seen tutorials popping up in numerous places showing off the abilities of Backbone.js and teaching users how to utilize the power of this amazing library. I feel like I can do no less than bestow the same type of knowledge upon you – my readers – so I’ve started a video series. The first 5 videos will teach you about the individual modules of Backbone.js, and then I’ll walk step by step through making a simple web application with Backbone.js. I’ll be updating the list of released tutorials below.
Backbone.js Video Tutorial Series
- Backbone.js Part 1: Models
- Backbone.js Part 2: Views
- Backbone.js Part 3: Routers
- Backbone.js Part 4: Collections
- Backbone.js Part 5: AJAX
- Backbone App Walkthrough Part 1: HTML and Models
- Backbone App Walkthrough Part 2: Views and Templates
- Backbone App Walkthrough Part 3: New View and External Templating
- Backbone App Walkthrough Part 4: It Lives!
- Backbone App Walkthrough Part 5: RequireJS