Chapter 4. Exercise 1: Todos—Your First Backbone.js App
Now that we’ve covered fundamentals, let’s write our first Backbone.js application. We’ll build the Backbone Todo List application exhibited on TodoMVC.com. Building a todo list is a great way to learn Backbone’s conventions (see Figure 4-1). It’s a relatively simple application, yet technical challenges surrounding binding, persisting model data, routing, and template rendering provide opportunities to illustrate some core Backbone features.
Let’s consider the application’s architecture at a high level. We’ll need:
A Todo model to describe individual todo items
A
TodoListcollection to store and persist todosA way of creating todos
A way to display a listing of todos
A way to edit existing todos
A way to mark a todo as completed
A way to delete todos
A way to filter the items that have been completed or are remaining

Figure 4-1. A todo list—the first Backbone.js application we will be writing
Essentially, these features are classic CRUD (create, read, update, delete) methods. Let’s get started!
Static HTML
We’ll place all of our HTML in a single file named index.html.
Header and Scripts
First, we’ll set up the header and the basic application dependencies: jQuery, Underscore, Backbone.js, and the Backbone localStorage adapter.
<!doctype html><htmllang="en"><head><metacharset="utf-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge,chrome=1" ...
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.
Read now
Unlock full access