Facebook Pixel
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 2013 371 pages
3.69
100+ ratings
Listen

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:

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:

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.91 MB     Pages: 9

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
0:00
-0:00
1x
Dan
Andrew
Michelle
Lauren
Select Speed
1.0×
+
200 words per minute
Create a free account to unlock:
Bookmarks – save your favorite books
History – revisit books later
Ratings – rate books & see your ratings
Unlock unlimited listening
Your first week's on us!
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 Nov 28,
cancel anytime before.
Compare Features Free Pro
Read full text summaries
Summaries are free to read for everyone
Listen to summaries
12,000+ hours of audio
Unlimited Bookmarks
Free users are limited to 10
Unlimited History
Free users are limited to 10
What our users say
30,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/yr
$3.75/mo
Monthly
$9.99/mo
Try Free & Unlock
7 days free, then $44.99/year. Cancel anytime.
Settings
Appearance