Skip to Content
Learning JavaScript Design Patterns
book

Learning JavaScript Design Patterns

by Addy Osmani
July 2012
Intermediate to advanced content levelIntermediate to advanced
254 pages
6h 16m
English
O'Reilly Media, Inc.
Content preview from Learning JavaScript Design Patterns

Backbone.js Versus KnockoutJS

Understanding the subtle differences between MVC, MVP, and MVVM is important, but developers ultimately will ask whether they should consider using KnockoutJS over Backbone based in what we’ve learned. The following notes may be of help here:

  • Both libraries are designed with different goals in mind, and it’s often not as simple as just choosing MVC or MVVM.

  • If data binding and two-way communication are your main concerns, KnockoutJS is definitely the way to go. Practically any attribute or value stored in DOM nodes can be mapped to JavaScript objects with this approach.

  • Backbone excels with its ease of integration with RESTful services, while KnockoutJS Models are simply JavaScript objects and code needed for updating the Model must be written by the developer.

  • KnockoutJS has a focus on automating UI bindings, which requires significantly more verbose custom code if attempting to do this with Backbone. This isn’t a problem with Backbone itself per se, as it purposefully attempts to stay out of the UI. Knockback does, however, attempt to assist with this problem.

  • With KnockoutJS, we can bind our own functions to ViewModel observables, which are executed any time the observable changes. This allows us the same level of flexibility as can be found in Backbone.

  • Backbone has a solid routing solution built in, while KnockoutJS offers no routing options out of the box. One can, however, easily fill in this behavior if needed using Ben Alman’s BBQ plug-in or a standalone ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Design Patterns - Second Edition

Mastering JavaScript Design Patterns - Second Edition

Simon Timms
JavaScript Patterns

JavaScript Patterns

Stoyan Stefanov

Publisher Resources

ISBN: 9781449334840Errata Page