Book Image

Backbone.js Patterns and Best Practices

By : Swarnendu De
Book Image

Backbone.js Patterns and Best Practices

By: Swarnendu De

Overview of this book

Table of Contents (19 chapters)
Backbone.js Patterns and Best Practices
About the Author
About the Reviewers
Precompiling Templates on the Server Side

Chapter 6. Working with Events, Sync, and Storage

In the previous chapters, we discussed each Backbone component (view, model, collection, and router) separately and in detail. In this chapter, we are going to talk about the custom events, Backbone.sync() method and Backbone.LocalStorage. Though these topics are not exactly related to each other, we placed them in a single chapter as we need to cover each one of them before we move on to application architecture and patterns in the next chapter.

Events are always considered as one of the most powerful concepts in JavaScript. They are a representation of the observer pattern (a well-known design pattern for loose coupling) and are used by most JavaScript libraries. In Backbone, Backbone.Events is a nontrivial module that can be used with any object to have event-related functionality. This is how Backbone.Events is defined in the Backbone documentation (

Event is a module that can be mixed in to any object, giving...