Book review: Backbone.js patterns and best practices

I developed a few large scale apps with Backbone.js and always looking to improve the way I’m developing these apps, there is always something new (patterns, plugins, frameworks, libraries, etc). So I picked up this book and decided to give it a try. I have teamed up with Packt Publishing to organize a giveaway of the book. Keep reading to find out how you can be one of the Lucky Winners.

Backbone Practices

In general it’s not the book for beginner JavaScript developer and not even good intro book to Backbone.js, this book is for medium and advanced Backbone.js developers, who already used it in multiple projects and ready to improve the workflow and organize the code like a pro.

It starts with describing some of the basics of object oriented JavaScript. Mixins is a great tool in object oriented JavaScript and let’s developer re-use a lot of code by including or extending some of the existing classes or objects, in this case using Underscore.js _.extend() function. The book goes into great detail explaining what is mixin and how to use it. Also some general Backbone.js structure like a base class. View Basics – tag names, el, templates, rendering and events. Great point on using ListenTo vs. On methods and why it’s different, partial view update (change:address) vs sub view (nested view), avoiding multiple DOM reflows.

The author goes into some details about Marionette views and why using frameworks like that is necessary when dealing with large scale Backbone.js project. For example CollectionView takes care of creating, adding and removing child views. I agree that sometimes Backbone.js alone is not enough and using third party libraries like Marionette or Layout manager plugin helps a lot.

The part of the book about Models describes basics of models in Backbone.js and some of their methods like fetch, destroy, validation, serializing etc. Especially author explains a lot about validation and validation plugin. I really like chapter about Relational Data model and Backbone-relational plugin, I learned myself about model relationship in Backbone and how to handle these relationships in complex apps.

Chapter on router describes basics of routers, avoiding large code in the routes. Author explains why it is better to create separate function and call it inside your router, my approach to this is a bit different but the one described here in the book works totally fine too. Great point on using regular expressions and sub routes in router – very handy. Custom events and event dispatcher that something I’ve never used in my apps, but definitely great tool for organizing your events across entire app.

Knowing how to organize your code is very important for maintenance and things like require.js, app directory structure (html, js), global objects are great just for that.

Majority of web developers believe that testing is essential, but in reality only a few of them actually do test-driven development. I’m one of those developers that don’t do testing. So I was glad to see entire chapter dedicated to unit testing.

Overall this is a great book if you want to refresh your knowledge about Backbone.js and if you want to take your code structure and best practices to the next level.

Giveaway

How to Enter?
All you need to do is head on over to the book page and look through the product description of the book and drop a line via the comments below this post to let me know what interests you the most about this book. It’s that simple. Winners will get an e-copy of the Book.

DeadlineThe contest will close on March 20, 2014. Winners will be contacted by email, so be sure to use your real email address when you comment!

16 thoughts on “Book review: Backbone.js patterns and best practices

  1. I looked through the table of contents and it seems like this book contains a solid coverage on the best practices of structuring backbone js apps. The sections on routing and events are a must-read I guess.

  2. I am Java developer and recently I started looking at some JS server (Node…).
    Backbone seems as something that fill a gap I was looking for.
    How to organize JS code.

    Looks interesting book to understand that.

  3. Backbone provides strong flexibility in build web applications, which is great, but, on the other hand, because of the same, one thing (e.g. sub layouts managing or sub routes) can be done in many ways, which in some cases, when a not optimal approach is chosen, might when application becomes bigger and bigger. Because of this, it is really important to use the best practices and patterns (previously verified by other developers in different projects) when building all kind of size Backbone apps
    Based on description of the book, it provides ready solutions for that. It will be great to read it.

  4. Hi Alex,

    I did couple of simple backbone projects, but never really got to testing them. So the last chapter explaining how to do it properly sounds very interesting to me.

  5. We’re in talks to reorganize/re architect/fix our mishmash/band-aid architecture. Getting the team knowledgeable about AMD and design pattern before starting will definitely help.

  6. I would love this. Ive been trying to learn a few different frameworks to help my career out and books have always been better for me to learn from!

  7. I would really be interested in best practice how to structure backbone apps :

    Chapter 7: Organizing Backbone Applications – Structure, Optimize, and Deploy

  8. Hello,

    This book looks great. I have been searching for something that covers both template management and the architecture aspect of Backbone.js.

  9. “Precompiling Templates on the Server Side”

    It relieves work from the client and makes your pages easier to index, which is quite desirable. I’d be interested in knowing best practices for doing that. I’m quite concerned about scalability, in general.

Leave a Reply

Your email address will not be published. Required fields are marked *

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