Catalog / Backbone.js Cheat Sheet
Backbone.js Cheat Sheet
A concise reference for Backbone.js, covering models, views, collections, routers, and events, along with best practices for building structured JavaScript applications.
Backbone.js Fundamentals
Core Concepts
Models: Represent data and business logic. |
Backbone.js is a lightweight framework that provides structure to JavaScript applications by introducing models with key-value binding and custom events, collections with a rich API of enumerated functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface. |
Setting up Backbone
Include Backbone.js library |
|
Dependencies |
Backbone.js depends on Underscore.js and jQuery (or Zepto.js). |
Backbone Object
The |
It provides methods for creating models, views, collections, and routers. |
Models & Collections
Model Definition
|
Define a Model by extending |
|
|
Model Attributes
Get Attribute |
|
Set Attribute |
|
Check if Attribute Exists |
|
Collection Definition
|
Define a Collection by extending |
|
Collection Operations
Add Model |
|
Remove Model |
|
Fetch Models from Server |
|
Filter Models |
|
Views & Events
View Definition
|
Define a View by extending |
|
|
|
Event Handling
View Events |
|
Model Events |
|
Collection Events |
|
Rendering Views
Views are rendered by populating the DOM with data from the model. Use templates (e.g., Underscore templates, Handlebars) to generate HTML. |
|
Routers & Best Practices
Router Definition
|
Define a Router by extending |
|
Navigation
Navigate to Route |
|
Start History |
|
Best Practices
|
|