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

Understanding automatic model-view data binding

Whenever an attribute of the attached model changes, we refresh the view to display the updated data. A change event listener is attached to the model inside the initialize() method of the view as follows:

this.listenTo(this.model, 'change', this.render);

However, there are options that can handle this data binding automatically and you do not need to take care of it for every model-view relationship. This principle is more aligned towards the MVVM design pattern than the Backbone's MV* pattern, and you will find it in frameworks such as Knockout.js and Meteor.js.

For Backbone, there are multiple plugins such as Backbone.Stickit (, Backbone.ModelBinder (, and Rivets.js ( These plugins provide a similar data binding feature. We are not going to discuss each plugin here; however, the implementation process is simple and similar...