Beginning Backbone: My First Book

BookCoverIt’s been a long time ambition of mine to write a technical book. In the second half of 2013, I finally got the opportunity to do that, publishing Beginning Backbone.js with Apress. The book is available to purchase now, in all the usual formats.

Read (or scroll, but I’d prefer you read!) to the end of this post to get an excellent 30% off the ebook price until January 23)

Who’s The Book For? Everyone

When planning this book, I had a number of different readers in mind. As such, I feel that I’ve written this book to appeal across the board. JavaScript novices will find the book useful, as it starts at the simplest level. At the same time, experts should find this to be an excellent way to learn Backbone inside out.

I also wanted this book to appeal to CTOs, who are hearing that Backbone is (or isn’t) the next best thing for their web app: this book will help them form their own opinion. Finally, the book will assist teams who are getting to grips with large scale JavaScript application development.  With chapters covering test driven development, best practices and continuous integration, the book shows the level of maturity that JavaScript has reached.

What’s Backbone?  

At this point, I’m sure most people have heard about Backbone, a library that helps organise your JavaScript code in a structured Model View * format. The thing that I like most about Backbone is that it is un-opinionated, unlike Angular and Meteor. While this results in the developer needing to write more boilerplate code, it gives a very comfortable level of control. More about this later, as it is one of the most contentious issues in JavaScript framework selection these days.

What’s in the Book?

There are a number of different sections in the book that deal with different issues.

The Introductory Section

The first two chapters are designed to ease the reader into the web application development world. This first group of chapters introduce Backbone and similar libraries, along with going back-to-basics on object oriented JavaScript. If you’re rusty,it’s worth reading through this chapter to strengthen your understanding of what the language provides before diving into the library itself.

The Nuts & Bolts Section 

The next batch of three chapters bring in the main concepts that exist in Backbone: Models, Collections, Views, Routers and Events. When going through the code examples in these chapters, a node.js server is used to provide a  REST API. While the depth in which node.js is explored is limited, I feel this a bonus for front-end developers. Each of these chapters iterates from the simplest possible version and then shows how additional configuration add more power.

I am particularly proud of the chapter that discusses Backbone Views. In true un-opinionated fashion, I explain how to use three of the leading template libraries for your views: Underscore, Handlebars and Mustache. Using a template library means that you get to avoid polluting your JavaScript with HTML strings. All three libraries listed have their own brilliances, but I find it difficult to beat Handlebars.

With this knowledge, Chapter 6 goes from start to finish with a complete application example. For this I went with Twitter, as it provides an easily understandable API. This gives the opportunity to use a Models, Collections, Routers and many different views on a single page. You end up with something that looks like the picture below.


The Extending Backbone Section

From the point, the book changes tone slightly. First I take a look at the huge number of extensions that have been written by the Backbone developer community. Here’s where the naysayers should look, if they feel that Backbones lack of data-view binding is hampering their progress. There are extensions available to help you out of almost any problem that you feel Backbone has. The beauty of this is that you can easily integrate most of these plugins in your Backbone applications. And it’s just as simple to take them out.

Similar to this chapter, Chapter 10 looks at Backbone Marionette and Thorax. These are amazing additions to Backbone, and deserved their own chapter. To put both through their paces, the Twitter sample application is refactored to utilise the features they provide.

The Discipline Section

With all this code, you’re going to need some discipline. That’s where the test driven development chapter will help. The most popular JavaScript testing frameworks out there are Jasmine and QUnit, so these are both described in detail, illustrating how to test out that sample Twitter application.

The next chapter shows how to use Grunt to add continuous integration to your JavaScript development. Grunt is an amazingly powerful tool that no JavaScript developer should be without. As a developer who has come from the Java world, it’s great to see something that easily surpasses the power of Maven or Ant.

The Doing-It-Better Section

For anyone who is already using Backbone, the chapter on best practices will help them to improve on what they already know. These tips were gathered from a wide variety of sources, as well as from my own experiences. Then the book closes out with tips on making your code even more manageable by using Require.js to created a modular codebase.

That final chapter also shows how to use the amazing Yeoman when you need to start from scratch in your development. The Backbone generator that’s included is brilliant. And once you discover the starting point that Yeoman provides, you’ll never look back.

So, In Summary

As you can see, while to book focuses on Backbone as the core topic, it extends much further. It’s a book that covers everything that you need to know about using JavaScript, along with Backbone, in a professional software development environment. I really hope you do enjoy reading it, and using anything that you learn, as much as I enjoyed writing it.

If you like the sound of this, why not buy the book. Or how about this:  I can give you 30% off the price of the ebook if you purchase the book from the Apress site using the code BCKJ14.  

4 thoughts on “Beginning Backbone: My First Book

  1. Wipying on said:

    As a reader of your book titled “Beginning Backbone.js”, I have a question.
    In 40th page, you wrote, “When creating new model objects, you may want some behavior to be executed on construction, such assetting up
    different handlers or setting some initial state in your mode. ”
    I don’t understand this sentence.
    >> What is “your mode” in this sentence? and “assetting up” ?
    I guessed that there were some misspelling, but I also want to confirm of this.

    “When creating new model objects, you may want some behavior to be executed on construction, such as setting up
    different handlers or setting some initial state in your model. ”
    assetting up -> as setting up
    in your mode -> in your model
    Is this right?
    Sorry for my confusing

    • James on said:

      You’re right. There are a few typos in the early editions that should be resolved now.

      Hope you enjoyed the book

  2. dakala on said:


    Had a couple of issues with the server.js code. I’m running express 4.6.1 and apparently bodyParser has been deprecated along with the configure method in express 4.x.

    1. Installed body-parser:

    npm install body-parser

    2. Added the following code:

    var bodyParser = require('body-parser');

    3. Replaced:

    app.configure(function () {
    //Parses the JSON object given in the body request


    app.use(bodyParser.urlencoded({ extended: false }));

    3. Replaced:

    app.configure(function() {



Leave a Reply to dakala

Click here to cancel reply.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>