Searching...
English
EnglishEnglish
EspañolSpanish
简体中文Chinese
FrançaisFrench
DeutschGerman
日本語Japanese
PortuguêsPortuguese
ItalianoItalian
한국어Korean
РусскийRussian
NederlandsDutch
العربيةArabic
PolskiPolish
हिन्दीHindi
Tiếng ViệtVietnamese
SvenskaSwedish
ΕλληνικάGreek
TürkçeTurkish
ไทยThai
ČeštinaCzech
RomânăRomanian
MagyarHungarian
УкраїнськаUkrainian
Bahasa IndonesiaIndonesian
DanskDanish
SuomiFinnish
БългарскиBulgarian
עבריתHebrew
NorskNorwegian
HrvatskiCroatian
CatalàCatalan
SlovenčinaSlovak
LietuviųLithuanian
SlovenščinaSlovenian
СрпскиSerbian
EestiEstonian
LatviešuLatvian
فارسیPersian
മലയാളംMalayalam
தமிழ்Tamil
اردوUrdu
Developing Backbone.js Applications

Developing Backbone.js Applications

Building Better JavaScript Applications
by Addy Osmani 2012 371 pages
3.69
100+ ratings
Listen
Try Full Access for 7 Days
Unlock listening & more!
Continue

Key Takeaways

1. Backbone.js provides structure for complex JavaScript applications

Backbone.js is a lightweight JavaScript library that adds structure to your client-side code.

Organization and maintainability. Backbone.js offers a solution to the challenge of building complex JavaScript applications by providing a structured framework. It introduces the concept of models, views, and collections, which help separate concerns and organize code logically. This structure makes it easier to manage and maintain large-scale applications, reducing the likelihood of creating "spaghetti code" that becomes difficult to debug and extend over time.

Flexibility and minimalism. Unlike more opinionated frameworks, Backbone.js provides a minimal set of tools and conventions, allowing developers the freedom to implement their own architecture on top of its foundation. This flexibility makes Backbone suitable for a wide range of projects, from small single-page applications to large enterprise systems. The library's small size (around 7.6KB minified and gzipped) means it doesn't add significant overhead to your project, making it an attractive option for performance-conscious developers.

2. Models, views, and collections form the core of Backbone applications

Models are the heart of any JavaScript application, containing the interactive data as well as a large part of the logic surrounding it: conversions, validations, computed properties, and access control.

Data management with models. Backbone models encapsulate data and business logic, providing a clean interface for manipulating and validating data. They can be created, retrieved, updated, and deleted (CRUD operations) independently of the user interface. Models emit events when their data changes, allowing views to update automatically.

User interface with views. Views in Backbone are responsible for rendering the user interface and handling user interactions. They listen to model events and re-render themselves when the underlying data changes. This separation of concerns between data (models) and presentation (views) leads to more maintainable and testable code.

Data collections. Collections in Backbone are ordered sets of models, providing a rich API for working with arrays of data. They allow for:

  • Sorting and filtering of data
  • Aggregation of data across multiple models
  • Syncing data with the server
  • Emitting events when the collection changes

3. Routing enables single-page application functionality in Backbone

Backbone.Router provides methods for routing client-side pages, and connecting them to actions and events.

Client-side navigation. Backbone's router allows developers to create single-page applications (SPAs) by mapping URLs to functions. This enables users to navigate through an application without full page reloads, resulting in a smoother, more responsive user experience.

Deep linking and bookmarking. By using the router, developers can create bookmarkable URLs for different application states. This allows users to share specific views or return to previous states easily, enhancing the overall usability of the application.

History management. Backbone's router integrates with the browser's history API, enabling users to use the back and forward buttons as they would in a traditional multi-page application. This preserves the expected browsing behavior while taking advantage of the performance benefits of SPAs.

4. Events system allows for decoupled communication between components

Backbone.Events is a module that can be mixed in to any object, giving the object the ability to bind and trigger custom named events.

Loose coupling. The events system in Backbone allows different parts of an application to communicate without being directly dependent on each other. This promotes modularity and makes it easier to change or extend functionality without affecting the entire system.

Extensibility. By using custom events, developers can easily add new features or behaviors to existing components without modifying their core logic. This makes Backbone applications highly extensible and adaptable to changing requirements.

Reactive programming. The events system facilitates a reactive programming style, where changes in one part of the application automatically trigger updates in other parts. This can lead to more dynamic and responsive user interfaces, as well as simpler code that doesn't need to manually manage state changes across the application.

5. Modular development with RequireJS enhances maintainability

RequireJS implements the AMD Specification, which defines a method for writing modular code and managing dependencies.

Dependency management. RequireJS allows developers to define and manage dependencies between different parts of their application. This helps prevent global namespace pollution and makes it easier to understand and maintain the relationships between different modules.

Code organization. By using RequireJS, developers can organize their Backbone applications into smaller, more manageable files. This improves code readability and makes it easier for teams to work on different parts of the application simultaneously.

Optimization for production. RequireJS includes an optimization tool (r.js) that can combine and minify modules for production deployment. This results in faster load times and improved performance for end-users.

6. jQuery Mobile integration extends Backbone to mobile platforms

jQuery Mobile follows progressive enhancement and responsive web design principles using HTML5 markup-driven definitions and configurations.

Cross-platform development. Integrating jQuery Mobile with Backbone allows developers to create mobile-friendly applications using a familiar toolset. This enables the development of applications that work across a wide range of devices and screen sizes.

Progressive enhancement. jQuery Mobile's approach to progressive enhancement ensures that applications remain functional on older devices while providing enhanced experiences on more capable platforms. This aligns well with Backbone's flexible nature, allowing developers to create applications that gracefully adapt to different environments.

Mobile-specific UI components. jQuery Mobile provides a set of touch-optimized UI components that can be easily integrated into Backbone views. This speeds up development of mobile applications and ensures a consistent, native-like experience across different mobile platforms.

7. Testing Backbone apps ensures reliability and facilitates maintenance

Unit testing is the process of taking the smallest piece of testable code in an application, isolating it from the remainder of your codebase, and determining if it behaves exactly as expected.

Improved code quality. Writing tests for Backbone applications helps identify bugs early in the development process and ensures that individual components work as expected. This leads to more reliable and stable applications.

Refactoring confidence. A comprehensive test suite gives developers the confidence to refactor and improve their code without fear of introducing regressions. This is particularly important in Backbone applications, where changes to models or collections can have far-reaching effects.

Documentation through tests. Well-written tests serve as documentation for how different parts of a Backbone application should behave. This can be invaluable for onboarding new team members or understanding complex interactions within the system.

Testing frameworks and tools for Backbone applications include:

  • Jasmine: A behavior-driven development framework for testing JavaScript code
  • QUnit: A powerful JavaScript test suite often used with Backbone
  • SinonJS: A library for creating spies, stubs, and mocks in JavaScript tests

Last updated:

FAQ

1. What is "Developing Backbone.js Applications" by Addy Osmani about?

  • Comprehensive Backbone.js guide: The book offers an in-depth introduction to Backbone.js, a lightweight JavaScript framework for structuring client-side web applications.
  • Core concepts covered: It explains models, views, collections, routers, and how to build maintainable, modular single-page applications (SPAs).
  • Hands-on learning: Readers are guided through practical projects like a Todo app and a Book Library app, with step-by-step exercises and real-world examples.
  • Advanced topics included: The book also explores modular development, RESTful integration, testing, optimization, and popular Backbone extensions.

2. Why should I read "Developing Backbone.js Applications" by Addy Osmani?

  • Improve client-side architecture: The book demonstrates how Backbone.js helps organize complex JavaScript-heavy applications, making code more maintainable and scalable.
  • Practical, real-world skills: Through detailed examples and exercises, readers learn to build, test, and optimize real applications using Backbone and related tools.
  • Covers advanced and common challenges: It addresses issues like modularization, memory management, and integration with other libraries, providing solutions for common Backbone.js pitfalls.
  • Open and community-driven resource: Released under a Creative Commons license, the book encourages community contributions and is accessible to novice and intermediate developers.

3. What are the key takeaways from "Developing Backbone.js Applications" by Addy Osmani?

  • Minimalist, flexible architecture: Backbone.js provides just enough structure—models, collections, views, and routers—without enforcing rigid patterns, allowing developers to adapt it to their needs.
  • Event-driven and RESTful: The framework’s event system keeps data and UI in sync, and it integrates easily with RESTful APIs for server communication.
  • Modular and scalable development: The book emphasizes modular code organization using AMD and RequireJS, making large applications maintainable and efficient.
  • Testing and optimization: Readers learn best practices for testing with Jasmine and QUnit, and for optimizing production builds with tools like r.js.

4. What are the best quotes from "Developing Backbone.js Applications" and what do they mean?

  • Minimal set of primitives: “The essential premise at the heart of Backbone has always been to try and discover the minimal set of data-structuring (Models and Collections) and user interface (Views and URLs) primitives that are useful when building web applications with JavaScript.” This highlights Backbone’s philosophy of simplicity and sufficiency.
  • Embracing new perspectives: “One’s destination is never a place, but a new way of seeing things.” — Henry Miller. This quote encourages developers to adopt new approaches, like Backbone, to improve their craft.
  • Importance of namespacing: “Without strong namespacing conventions, it is also fairly easy to pollute the global namespace with your own custom objects.” This underscores the need for modularity and clean code organization in JavaScript.

5. How does "Developing Backbone.js Applications" by Addy Osmani explain the MVC pattern and Backbone’s MV* approach?

  • MVC basics explained: The book describes MVC as separating concerns into Models (data), Views (UI), and Controllers (input handling), with clear communication between components.
  • Backbone’s MV variation:* Backbone merges controller responsibilities into views and uses routers for navigation, making it an MV* rather than strict MVC framework.
  • Event-driven updates: Models and views communicate via an event system, keeping data and UI synchronized without direct coupling.
  • Templating and routing: Views render templates (like Underscore or Handlebars), and routers manage application state and navigation for SPAs.

6. How do Backbone.js models, views, collections, and routers work according to Addy Osmani’s book?

  • Models: Hold data attributes, support defaults and validation, and can persist data to a server using RESTful methods like save(), fetch(), and destroy().
  • Views: Manage UI logic, render templates, and handle DOM events declaratively, listening to model changes to update the interface.
  • Collections: Ordered sets of models with utility methods for adding, removing, filtering, and sorting, and can fetch data from servers.
  • Routers: Map URL fragments to functions, enabling bookmarkable states and navigation in single-page applications.

7. What are the key features and benefits of Backbone.js highlighted in "Developing Backbone.js Applications"?

  • Lightweight and flexible: Backbone provides minimal structure, allowing developers to build applications in their preferred style.
  • Event-driven and RESTful: Rich event handling between models and views, and seamless integration with RESTful APIs for data persistence.
  • Modular and scalable: Scales from small widgets to large applications, and works well with other libraries and frameworks.
  • Readable and efficient: The source code is small and accessible, making it easy for developers to understand and extend.

8. How does Addy Osmani’s book guide building a Todo application with Backbone.js?

  • Step-by-step architecture: The book walks through creating Todo models, collections, and views, demonstrating CRUD operations and UI binding.
  • Templates and events: Uses Underscore.js templates for rendering and declarative event handling for user interactions like adding, editing, and deleting todos.
  • Persistence with localStorage: Shows how to use Backbone.localStorage to persist data in the browser without a server.
  • Routing and filtering: Implements URL-based filtering (all, active, completed) using Backbone.Router for bookmarkable app states.

9. How does "Developing Backbone.js Applications" by Addy Osmani recommend integrating Backbone.js with a RESTful backend?

  • Separation of concerns: The frontend Backbone app communicates with a Node.js/Express REST API backend, modeling real-world client-server interaction.
  • Model and collection setup: Models and collections are configured with URLs pointing to the REST API, enabling fetch(), save(), and destroy() to sync with the server.
  • Handling nested data: The book addresses challenges like date formatting and nested attributes, showing how to parse and serialize data correctly.
  • Server-side implementation: Guides setting up a MongoDB-backed REST API with CRUD routes, connecting Backbone apps to persistent storage.

10. What are MarionetteJS and Thorax, and how do they extend Backbone.js as described in Addy Osmani’s book?

  • MarionetteJS: A composite application library that reduces boilerplate, manages memory and view lifecycles, and provides specialized view types and regions for layout management.
  • Boilerplate reduction: Automates rendering logic and view cleanup, preventing memory leaks and zombie views.
  • Thorax: An opinionated framework built on Backbone, using Handlebars templating and offering conventions for app organization and embedding child views.
  • Flexibility and modularity: Both extensions allow developers to scale Backbone apps with better structure and maintainability, integrating seamlessly with existing code.

11. How does "Developing Backbone.js Applications" by Addy Osmani recommend modularizing applications using RequireJS and AMD?

  • Asynchronous module loading: RequireJS loads JavaScript files asynchronously, improving performance and enabling dynamic module loading.
  • AMD module definition: Modules are defined with define(), specifying dependencies and a factory function for clean dependency management.
  • External templates and shimming: Uses RequireJS’s text.js plug-in for external templates and configures shims for non-AMD libraries like Backbone and Underscore.
  • Organizing code: Encourages separating models, views, collections, and routers into folders, wrapping components as AMD modules for maintainability.

12. How does Addy Osmani’s book approach testing Backbone.js applications with Jasmine, QUnit, and SinonJS?

  • Jasmine for BDD: Introduces Jasmine as a behavior-driven development framework for writing readable, automated unit tests with suites, specs, and spies.
  • Testing models, collections, and views: Provides examples for testing defaults, validation, filtering, rendering, and DOM integration, using jasmine-jquery for fixtures.
  • Asynchronous and spy support: Shows how to mock AJAX requests and write asynchronous tests, ensuring thorough client-server interaction testing.
  • Comparison with QUnit and SinonJS: Explains QUnit’s straightforward assertions and modules, and how SinonJS adds spies, stubs, and mocks for detailed function call inspection.

Review Summary

3.69 out of 5
Average of 100+ ratings from Goodreads and Amazon.

Developing Backbone.js Applications receives mixed reviews, with an average rating of 3.69 out of 5. Readers appreciate its comprehensive coverage of Backbone.js and related technologies, praising the logical flow and good examples. However, some find it better suited for intermediate to advanced users rather than beginners. Critics note outdated content, incomplete code examples, and a lack of in-depth explanations. Despite these drawbacks, many still consider it a valuable resource for learning Backbone.js, especially when combined with hands-on practice and additional documentation.

Your rating:
4.23
36 ratings

About the Author

Addy Osmani is a Senior Staff Engineering Manager at Google Chrome, leading teams focused on improving web development efficiency and performance. He has authored multiple books and is a frequent speaker at international conferences. Osmani's expertise lies in making web development faster and more accessible for developers. His work at Google Chrome involves streamlining the web development process and enhancing the platform's capabilities. With his extensive experience and contributions to the field, Osmani has established himself as a respected figure in the web development community, known for his insights and practical approaches to modern web technologies.

Download PDF

To save this Developing Backbone.js Applications summary for later, download the free PDF. You can print it out, or read offline at your convenience.
Download PDF
File size: 0.19 MB     Pages: 10

Download EPUB

To read this Developing Backbone.js Applications summary on your e-reader device or app, download the free EPUB. The .epub digital book format is ideal for reading ebooks on phones, tablets, and e-readers.
Download EPUB
File size: 3.59 MB     Pages: 8
Listen
0:00
-0:00
1x
Dan
Andrew
Michelle
Lauren
Select Speed
1.0×
+
200 words per minute
Home
Library
Get App
Create a free account to unlock:
Requests: Request new book summaries
Bookmarks: Save your favorite books
History: Revisit books later
Recommendations: Personalized for you
Ratings: Rate books & see your ratings
100,000+ readers
Try Full Access for 7 Days
Listen, bookmark, and more
Compare Features Free Pro
📖 Read Summaries
All summaries are free to read in 40 languages
🎧 Listen to Summaries
Listen to unlimited summaries in 40 languages
❤️ Unlimited Bookmarks
Free users are limited to 4
📜 Unlimited History
Free users are limited to 4
📥 Unlimited Downloads
Free users are limited to 1
Risk-Free Timeline
Today: Get Instant Access
Listen to full summaries of 73,530 books. That's 12,000+ hours of audio!
Day 4: Trial Reminder
We'll send you a notification that your trial is ending soon.
Day 7: Your subscription begins
You'll be charged on Jun 7,
cancel anytime before.
Consume 2.8x More Books
2.8x more books Listening Reading
Our users love us
100,000+ readers
"...I can 10x the number of books I can read..."
"...exceptionally accurate, engaging, and beautifully presented..."
"...better than any amazon review when I'm making a book-buying decision..."
Save 62%
Yearly
$119.88 $44.99/year
$3.75/mo
Monthly
$9.99/mo
Try Free & Unlock
7 days free, then $44.99/year. Cancel anytime.
Scanner
Find a barcode to scan

Settings
General
Widget
Loading...