var vanHalen = new Backbone.Collection([eddie, alex, stone, roth]);
vanHalen.set([eddie, alex, stone, hagar]);
// Fires a "remove" event for roth, and an "add" event for "hagar".
// Updates any of stone, alex, and eddie's attributes that may have
// changed over the years.

F.A.Q.

Why use Backbone, not [other framework X]?
If your eye hasn't already been caught by the adaptability and elan on display
in the above list of examples, we can get more specific:
Backbone.js aims to provide the common foundation that data-rich web applications
with ambitious interfaces require — while very deliberately avoiding
painting you into a corner by making any decisions that you're
better equipped to make yourself.

Backbone does not force you to use a single template engine. Views can bind
to HTML constructed in
your
favoriteway.

It's smaller. There are fewer kilobytes for your browser or phone to download,
and less conceptual surface area. You can read and understand
the source in an afternoon.

It doesn't depend on stuffing application logic into your HTML.
There's no embedded JavaScript, template logic, or binding hookup code in
data- or ng- attributes, and no need to invent your own HTML tags.

Synchronous events are used as the fundamental
building block, not a difficult-to-reason-about run loop, or by constantly
polling and traversing your data structures to hunt for changes. And if
you want a specific event to be asynchronous and aggregated,
no problem.

Backbone is a library, not a framework, and plays well with others.
You can embed Backbone widgets in Dojo apps without trouble, or use Backbone
models as the data backing for D3 visualizations (to pick two entirely
random examples).

"Two-way data-binding" is avoided. While it certainly makes for a nifty
demo, and works for the most basic CRUD, it doesn't tend to be terribly
useful in your real-world app. Sometimes you want to update on
every keypress, sometimes on blur, sometimes when the panel is closed,
and sometimes when the "save" button is clicked. In almost all cases, simply
serializing the form to JSON is faster and easier. All that aside, if your
heart is set, gofor it.

There's no built-in performance penalty for choosing to structure your
code with Backbone. And if you do want to optimize further, thin models and
templates with flexible granularity make it easy to squeeze every last
drop of potential performance out of, say, IE8.

There's More Than One Way To Do It
It's common for folks just getting started to treat the examples listed
on this page as some sort of gospel truth. In fact, Backbone.js is intended
to be fairly agnostic about many common patterns in client-side code.
For example...

References between Models and Views can be handled several ways.
Some people like to have direct pointers, where views correspond 1:1 with
models (model.view and view.model). Others prefer to have intermediate
"controller" objects that orchestrate the creation and organization of
views into a hierarchy. Others still prefer the evented approach, and always
fire events instead of calling methods directly. All of these styles work well.

Feel free to define your own events.Backbone.Events
is designed so that you can mix it in to any JavaScript object or prototype.
Since you can use any string as an event, it's often handy to bind
and trigger your own custom events: model.on("selected:true") or
model.on("editing")

Render the UI as you see fit. Backbone is agnostic as to whether you
use Underscore templates,
Mustache.js, direct DOM
manipulation, server-side rendered snippets of HTML, or
jQuery UI in your render function.
Sometimes you'll create a view for each model ... sometimes you'll have a
view that renders thousands of models at once, in a tight loop. Both can be
appropriate in the same app, depending on the quantity of data involved,
and the complexity of the UI.

Nested Models & Collections
It's common to nest collections inside of models with Backbone. For example,
consider a Mailbox model that contains many Message models.
One nice pattern for handling this is have a this.messages collection
for each mailbox, enabling the lazy-loading of messages, when the mailbox
is first opened ... perhaps with MessageList views listening for
"add" and "remove" events.

If you're looking for something more opinionated, there are a number of
Backbone plugins that add sophisticated associations among models,
available on the wiki.

Backbone doesn't include direct support for nested models and collections
or "has many" associations because there are a number
of good patterns for modeling structured data on the client side, and
Backbone should provide the foundation for implementing any of them.
You may want to…

Mirror an SQL database's structure, or the structure of a NoSQL database.

Use models with arrays of "foreign key" ids, and join to top level
collections (a-la tables).

For associations that are numerous, use a range of ids instead of an
explicit list.

Lazily load joined models from the server, or lazily deserialize nested
models from JSON documents.

Loading Bootstrapped Models
When your app first loads, it's common to have a set of initial models that
you know you're going to need, in order to render the page. Instead of
firing an extra AJAX request to fetch them,
a nicer pattern is to have their data already bootstrapped into the page.
You can then use reset to populate your
collections with the initial data. At DocumentCloud, in the
ERB template for the
workspace, we do something along these lines:

You have to escape</ within the JSON string, to prevent javascript injection
attacks.

Extending Backbone
Many JavaScript libraries are meant to be insular and self-enclosed,
where you interact with them by calling their public API, but never peek
inside at the guts. Backbone.js is not that kind of library.

Because it serves as a foundation for your application, you're meant to
extend and enhance it in the ways you see fit — the entire source
code is annotated to make this easier
for you. You'll find that there's very little there apart from core
functions, and most of those can be overridden or augmented should you find
the need. If you catch yourself adding methods to Backbone.Model.prototype,
or creating your own base subclass, don't worry — that's how things are
supposed to work.

How does Backbone relate to "traditional" MVC?
Different implementations of the
Model-View-Controller
pattern tend to disagree about the definition of a controller. If it helps any, in
Backbone, the View class can also be thought of as a
kind of controller, dispatching events that originate from the UI, with
the HTML template serving as the true view. We call it a View because it
represents a logical chunk of UI, responsible for the contents of a single
DOM element.

Comparing the overall structure of Backbone to a server-side MVC framework
like Rails, the pieces line up like so:

Backbone.Model – Like a Rails model minus the class
methods. Wraps a row of data in business logic.

Backbone.Collection – A group of models on the client-side,
with sorting/filtering/aggregation logic.

Binding "this"
Perhaps the single most common JavaScript "gotcha" is the fact that when
you pass a function as a callback, its value for this is lost.
When dealing with events and callbacks in Backbone,
you'll often find it useful to rely on listenTo
or the optional context argument that many of Underscore
and Backbone's methods use to specify the this
that will be used when the callback is later invoked. (See
_.each,
_.map, and
object.on, to name a few).
View events are automatically bound to
the view's context for you.
You may also find it helpful to use
_.bind and
_.bindAll
from Underscore.js.

Working with Rails
Backbone.js was originally extracted from
a Rails application; getting
your client-side (Backbone) Models to sync correctly with your server-side
(Rails) Models is painless, but there are still a few things to be aware of.

By default, Rails versions prior to 3.1 add an extra layer of wrapping
around the JSON representation of models. You can disable this wrapping
by setting:

ActiveRecord::Base.include_root_in_json = false

... in your configuration. Otherwise, override
parse to pull model attributes out of the
wrapper. Similarly, Backbone PUTs and POSTs direct JSON representations
of models, where by default Rails expects namespaced attributes. You can
have your controllers filter attributes directly from params, or
you can override toJSON in Backbone to add
the extra wrapping Rails expects.

Examples

The list of examples that follows, while long, is not exhaustive. If you've
worked on an app that uses Backbone, please add it to the
wiki page of Backbone apps.

DocumentCloud

The DocumentCloud workspace
is built on Backbone.js, with Documents, Projects,
Notes, and Accounts all as Backbone models and collections.
If you're interested in history — both Underscore.js and Backbone.js
were originally extracted from the DocumentCloud codebase, and packaged
into standalone JS libraries.

USA Today

USA Today takes advantage of the modularity of
Backbone's data/model lifecycle — which makes it simple to create, inherit,
isolate, and link application objects — to keep the codebase both manageable and efficient.
The new website also makes heavy use of the Backbone Router to control the
page for both pushState-capable and legacy browsers.
Finally, the team took advantage of Backbone's Event module to create a
PubSub API that allows third parties and analytics packages to hook into the
heart of the app.

Rdio

New Rdio was developed from the ground
up with a component based framework based on Backbone.js. Every component
on the screen is dynamically loaded and rendered, with data provided by the
Rdio API. When changes are pushed,
every component can update itself without reloading the page or interrupting
the user's music. All of this relies on Backbone's views and models,
and all URL routing is handled by Backbone's Router. When data changes are
signaled in realtime, Backbone's Events notify the interested components
in the data changes. Backbone forms the core of the new, dynamic, realtime
Rdio web and desktop applications.

Hulu

Hulu used Backbone.js to build its next
generation online video experience. With Backbone as a foundation, the
web interface was rewritten from scratch so that all page content can
be loaded dynamically with smooth transitions as you navigate.
Backbone makes it easy to move through the app quickly without the
reloading of scripts and embedded videos, while also offering models and
collections for additional data manipulation support.

Quartz

Quartz sees itself as a digitally native news
outlet for the new
global economy. Because Quartz believes in the future of open,
cross-platform web applications, they selected Backbone and Underscore
to fetch, sort, store, and display content from a custom WordPress
API. Although qz.com uses responsive design
for phone, tablet, and
desktop browsers, it also takes advantage of Backbone events and views
to render device-specific templates in some cases.

Earth

Earth.nullschool.net displays real-time weather
conditions on an interactive animated globe, and Backbone provides the
foundation upon which all of the site's components are built. Despite the
presence of several other javascript libraries, Backbone's non-opinionated
design made it effortless to mix-in the Events functionality used for
distributing state changes throughout the page. When the decision was made
to switch to Backbone, large blocks of custom logic simply disappeared.

Gawker Media

Kinja is Gawker Media's publishing platform designed
to create great stories by breaking down the lines between the traditional
roles of content creators and consumers. Everyone — editors, readers,
marketers — have access to the same tools to engage in passionate discussion
and pursue the truth of the story. Sharing, recommending, and following within the
Kinja ecosystem allows for improved information discovery across all the sites.

Kinja is the platform behind
Gawker,
Gizmodo,
Lifehacker,
io9 and other Gawker Media
blogs. Backbone.js underlies the front-end application code that powers
everything from user authentication to post authoring, commenting, and even serving
ads. The JavaScript stack includes
Underscore.js and
jQuery, with some plugins,
all loaded with
RequireJS. Closure templates are shared between the
Play! Framework based Scala application and Backbone views, and the responsive layout
is done with the
Foundation framework using
SASS.

Flow

MetaLab used Backbone.js to create
Flow, a task management app for teams. The
workspace relies on Backbone.js to construct task views, activities, accounts,
folders, projects, and tags. You can see the internals under window.Flow.

Gilt Groupe

Gilt Groupe uses Backbone.js to build multiple
applications across their family of sites.
Gilt's mobile website uses Backbone and
Zepto.js to create a blazing-fast
shopping experience for users on-the-go, while
Gilt Live combines Backbone with
WebSockets to display the items that customers are buying in real-time. Gilt's search
functionality also uses Backbone to filter and sort products efficiently
by moving those actions to the client-side.

Enigma

Enigma is a portal amassing the largest
collection of public data produced by governments, universities, companies,
and organizations. Enigma uses Backbone Models and Collections to represent
complex data structures; and Backbone's Router gives Enigma users unique URLs for
application states, allowing them to navigate quickly through the site while
maintaining the ability to bookmark pages and navigate forward and backward
through their session.

NewsBlur

NewsBlur is an RSS feed reader and
social news network with a fast and responsive UI that feels like a
native desktop app. Backbone.js was selected for
a major rewrite and transition from spaghetti code
because of its powerful yet simple feature set, easy integration, and large
community. If you want to poke around under the hood, NewsBlur is also entirely
open-source.

WordPress.com

WordPress.com is the software-as-a-service
version of WordPress. It uses Backbone.js
Models, Collections, and Views in its
Notifications system. Backbone.js was selected
because it was easy to fit into the structure of the application, not the
other way around. Automattic
(the company behind WordPress.com) is integrating Backbone.js into the
Stats tab and other features throughout the homepage.

Foursquare

Foursquare is a fun little startup that helps you meet up with friends,
discover new places, and save money. Backbone Models are heavily used in
the core JavaScript API layer and Views power many popular features like
the homepage map and
lists.

Bitbucket

Bitbucket is a free source code hosting
service for Git and Mercurial. Through its models and collections,
Backbone.js has proved valuable in supporting Bitbucket's
REST API, as well as newer
components such as in-line code comments and approvals for pull requests.
Mustache templates provide server and client-side rendering, while a custom
Google Closure
inspired life-cycle for widgets allows Bitbucket to decorate existing DOM
trees and insert new ones.

Disqus

Disqus chose Backbone.js to power the
latest version of their commenting widget. Backbone’s small
footprint and easy extensibility made it the right choice for Disqus’
distributed web application, which is hosted entirely inside an iframe and
served on thousands of large web properties, including IGN, Wired, CNN, MLB, and more.

Delicious

Delicious is a social bookmarking
platform making it easy to save, sort, and store bookmarks from across
the web. Delicious uses Chaplin.js,
Backbone.js and AppCache to build a full-featured MVC web app.
The use of Backbone helped the website and
mobile apps share a
single API service, and the reuse of the model tier made it significantly
easier to share code during the recent Delicious redesign.

Khan Academy

Khan Academy is on a mission to
provide a free world-class education to anyone anywhere. With thousands of
videos, hundreds of JavaScript-driven exercises, and big plans for the
future, Khan Academy uses Backbone to keep frontend code modular and organized.
User profiles and goal setting are implemented with Backbone,
jQuery and
Handlebars, and most new feature
work is being pushed to the client side, greatly increasing the quality of
the API.

IRCCloud

IRCCloud
is an always-connected IRC client that you use in your
browser — often leaving it open all day in a tab.
The sleek web interface communicates with an
Erlang backend via websockets and the
IRCCloud API.
It makes heavy use of Backbone.js events, models, views and routing to keep
your IRC conversations flowing in real time.

Pitchfork

Pitchfork uses Backbone.js to power
its site-wide audio player, Pitchfork.tv,
location routing, a write-thru page fragment cache, and more. Backbone.js
(and Underscore.js) helps the team
create clean and modular components,
move very quickly, and focus on the site, not the spaghetti.

Spin

Spin pulls in the
latest news stories from
their internal API onto their site using Backbone models and collections, and a
custom sync method. Because the music should never stop playing,
even as you click through to different "pages", Spin uses a Backbone router
for navigation within the site.

ZocDoc

ZocDoc helps patients
find local, in-network doctors and dentists, see their real-time
availability, and instantly book appointments.
On the public side, the webapp uses Backbone.js to handle client-side state and rendering in
search pages
and doctor profiles.
In addition, the new version of the doctor-facing part of the website is a
large single-page application that
benefits from Backbone's structure and modularity. ZocDoc's Backbone
classes are tested with
Jasmine, and delivered
to the end user with
Cassette.

Walmart Mobile

Walmart used Backbone.js to create the new version
of their mobile web application and
created two new frameworks in the process.
Thorax provides mixins, inheritable
events, as well as model and collection view bindings that integrate directly with
Handlebars templates.
Lumbar allows the application to be
split into modules which can be loaded on demand, and creates platform specific builds
for the portions of the web application that are embedded in Walmart's native Android
and iOS applications.

Groupon Now!

Groupon Now! helps you find
local deals that you can buy and use right now. When first developing
the product, the team decided it would be AJAX heavy with smooth transitions
between sections instead of full refreshes, but still needed to be fully
linkable and shareable. Despite never having used Backbone before, the
learning curve was incredibly quick — a prototype was hacked out in an
afternoon, and the team was able to ship the product in two weeks.
Because the source is minimal and understandable, it was easy to
add several Backbone extensions for Groupon Now!: changing the router
to handle URLs with querystring parameters, and adding a simple
in-memory store for caching repeated requests for the same data.

Basecamp

37Signals chose Backbone.js to create
the calendar feature of its
popular project management software Basecamp.
The Basecamp Calendar uses Backbone.js models and views in conjunction with the
Eco templating system to
present a polished, highly interactive group scheduling interface.

Slavery Footprint

Slavery Footprint
allows consumers to visualize how their consumption habits are
connected to modern-day slavery and provides them with an opportunity
to have a deeper conversation with the companies that manufacture the
goods they purchased.
Based in Oakland, California, the Slavery Footprint team works to engage
individuals, groups, and businesses to build awareness for and create
deployable action against forced labor, human trafficking, and modern-day
slavery through online tools, as well as off-line community education and
mobilization programs.

Stripe

Stripe provides an API for accepting
credit cards on the web. Stripe's
management interface was recently
rewritten from scratch in CoffeeScript using Backbone.js as the primary
framework, Eco for templates, Sass for stylesheets, and Stitch to package
everything together as CommonJS modules. The new app uses
Stripe's API directly for the
majority of its actions; Backbone.js models made it simple to map
client-side models to their corresponding RESTful resources.

SoundCloud Mobile

SoundCloud is the leading sound sharing
platform on the internet, and Backbone.js provides the foundation for
SoundCloud Mobile. The project uses
the public SoundCloud API
as a data source (channeled through a nginx proxy),
jQuery templatestemplates
for the rendering, Qunit
and PhantomJS for
the testing suite. The JS code, templates and CSS are built for the
production deployment with various Node.js tools like
ready.js,
Jake,
jsdom.
The Backbone.History was modified to support the HTML5 history.pushState.
Backbone.sync was extended with an additional SessionStorage based cache
layer.

Art.sy

Art.sy is a place to discover art you'll
love. Art.sy is built on Rails, using
Grape to serve a robust
JSON API. The main site is a single page
app written in CoffeeScript and uses Backbone to provide structure around
this API. An admin panel and partner CMS have also been extracted into
their own API-consuming Backbone projects.

Pandora

When Pandora redesigned
their site in HTML5, they chose Backbone.js to help
manage the user interface and interactions. For example, there's a model
that represents the "currently playing track", and multiple views that
automatically update when the current track changes. The station list is a
collection, so that when stations are added or changed, the UI stays up to date.

Inkling

Inkling is a cross-platform way to
publish interactive learning content.
Inkling for Web uses Backbone.js
to make hundreds of complex books — from student textbooks to travel guides and
programming manuals — engaging and accessible on the web. Inkling supports
WebGL-enabled 3D graphics, interactive assessments, social sharing,
and a system for running practice code right
in the book, all within a single page Backbone-driven app. Early on, the
team decided to keep the site lightweight by using only Backbone.js and
raw JavaScript. The result? Complete source code weighing in at a mere
350kb with feature-parity across the iPad, iPhone and web clients.
Give it a try with
this excerpt from JavaScript: The Definitive Guide.

Code School

Code School courses teach people
about various programming topics like CoffeeScript, CSS, Ruby on Rails,
and more. The new Code School course
challenge page
is built from the ground up on Backbone.js, using
everything it has to offer: the router, collections, models, and complex
event handling. Before, the page was a mess of jQuery DOM manipulation
and manual Ajax calls. Backbone.js helped introduce a new way to
think about developing an organized front-end application in JavaScript.

CloudApp

CloudApp is simple file and link
sharing for the Mac. Backbone.js powers the web tools
which consume the documented API
to manage Drops. Data is either pulled manually or pushed by
Pusher and fed to
Mustache templates for
rendering. Check out the annotated source code
to see the magic.

SeatGeek

SeatGeek's stadium ticket maps were originally
developed with Prototype.js. Moving to Backbone.js and jQuery helped organize
a lot of the UI code, and the increased structure has made adding features
a lot easier. SeatGeek is also in the process of building a mobile
interface that will be Backbone.js from top to bottom.

Easel

Easel is an in-browser, high fidelity web
design tool that integrates with your design and development
process. The Easel team uses CoffeeScript, Underscore.js and Backbone.js for
their rich visual editor as well as other
management functions throughout the site. The structure of Backbone allowed
the team to break the complex problem of building a visual editor into
manageable components and still move quickly.

Jolicloud

Jolicloud is an open and independent
platform and operating system
that provides music playback, video streaming, photo browsing and
document editing — transforming low cost computers into beautiful cloud devices.
The new Jolicloud HTML5 app was built
from the ground up using Backbone and talks to the
Jolicloud Platform, which is
based on Node.js. Jolicloud works offline using the HTML5 AppCache, extends
Backbone.sync to store data in IndexedDB or localStorage, and communicates
with the Joli OS via WebSockets.

Salon.io

Salon.io provides a space where photographers,
artists and designers freely arrange their visual art on virtual walls.
Salon.io runs on Rails, but does not use
much of the traditional stack, as the entire frontend is designed as a
single page web app, using Backbone.js, Brunch and
CoffeeScript.

Blossom

Blossom is a lightweight project management
tool for lean teams. Backbone.js is heavily used in combination with
CoffeeScript to provide a smooth
interaction experience. The app is packaged with Brunch.
The RESTful backend is built with Flask on Google App Engine.

Trello

Trello is a collaboration tool that
organizes your projects into boards. A Trello board holds many lists of
cards, which can contain checklists, files and conversations, and may be
voted on and organized with labels. Updates on the board happen in
real time. The site was built ground up using Backbone.js for all the
models, views, and routes.

Change Log

Backbone no longer tries to require jQuery in Node/CommonJS environments,
for better compatibility with folks using Browserify.
If you'd like to have Backbone use jQuery from Node, assign it like so:
Backbone.$ = require('jquery');

Backbone now registers itself for AMD (Require.js), Bower and Component,
as well as being a CommonJS module and a regular (Java)Script. Whew.

Added an execute hook to the Router, which allows you to hook
in and custom-parse route arguments, like query strings, for example.

Performance fine-tuning for Backbone Events.

Better matching for Unicode in routes, in old browsers.

Backbone Routers now handle query params in route fragments, passing
them into the handler as the last argument. Routes specified as
strings should no longer include the query string
('foo?:query' should be 'foo').

Renamed Collection's "update" to set, for
parallelism with the similar model.set(), and contrast with
reset. It's now the default
updating mechanism after a fetch. If you'd
like to continue using "reset", pass {reset: true}.

Your route handlers will now receive their URL parameters pre-decoded.

Added listenTo
and stopListening to Events. They
can be used as inversion-of-control flavors of on and off,
for convenient unbinding of all events an object is currently listening to.
view.remove() automatically calls view.stopListening().

When using add on a collection, passing {merge: true}
will now cause duplicate models to have their attributes merged in to
the existing models, instead of being ignored.

Added update (which is also available as
an option to fetch) for "smart" updating of sets of models.

While listening to a reset event, the list of previous models
is now available in options.previousModels, for convenience.

Validation now occurs even during "silent"
changes. This change means that the isValid method has
been removed. Failed validations also trigger an error, even if an error
callback is specified in the options.

Consolidated "sync" and "error" events within
Backbone.sync. They are now triggered regardless
of the existence of success or error callbacks.

For mixed-mode APIs, Backbone.sync now accepts
emulateHTTP and emulateJSON as inline options.

Removed getByCid from Collections. collection.get now
supports lookup by both id and cid.

After fetching a model or a collection, all defined parse
functions will now be run. So fetching a collection and getting back new
models could cause both the collection to parse the list, and then each model
to be parsed in turn, if you have both functions defined.

Bugfix for normalizing leading and trailing slashes in the Router
definitions. Their presence (or absence) should not affect behavior.

When declaring a View, options, el, tagName,
id and className may now be defined as functions, if
you want their values to be determined at runtime.

Added a Backbone.ajax hook for more convenient overriding of
the default use of $.ajax. If AJAX is too passé, set it to your
preferred method for server communication.

Collection#sort now triggers a sort event, instead
of a reset event.

Calling destroy on a Model will now return false if
the model isNew.

To set what library Backbone uses for DOM manipulation and Ajax calls,
use Backbone.$ = ... instead of setDomLibrary.

Removed the Backbone.wrapError helper method. Overriding
sync should work better for those particular use cases.

To improve the performance of add, options.index
will no longer be set in the `add` event callback.
collection.indexOf(model) can be used to retrieve the index
of a model as necessary.

For semantic and cross browser reasons, routes will now ignore search
parameters. Routes like search?query=…&page=3 should become
search/…/3.

Model#set no longer accepts another model as an argument. This leads
to subtle problems and is easily replaced with model.set(other.attributes).

Reverted to 0.5.3-esque behavior for validating models. Silent changes
no longer trigger validation (making it easier to work with forms).
Added an isValid function that you can use to check if a model
is currently in a valid state.

If you have multiple versions of jQuery on the page, you can now tell
Backbone which one to use with Backbone.setDomLibrary.

Fixes regressions in 0.9.0 for routing with "root", saving with
both "wait" and "validate", and the order of nested "change" events.

Creating and destroying models with create and destroy
are now optimistic by default. Pass {wait: true} as an option
if you'd like them to wait for a successful server response to proceed.

Two new properties on views: $el — a cached jQuery (or Zepto)
reference to the view's element, and setElement, which should
be used instead of manually setting a view's el. It will
both set view.el and view.$el correctly, as well as
re-delegating events on the new DOM element.

You can now bind and trigger multiple spaced-delimited events at once.
For example: model.on("change:name change:age", ...)

When you don't know the key in advance, you may now call
model.set(key, value) as well as save.

Multiple models with the same id are no longer allowed in a
single collection.

Added a "sync" event, which triggers whenever a model's state
has been successfully synced with the server (create, save, destroy).

bind and unbind have been renamed to on
and off for clarity, following jQuery's lead.
The old names are also still supported.

A Backbone collection's comparator function may now behave
either like a sortBy
(pass a function that takes a single argument),
or like a sort
(pass a comparator function that expects two arguments). The comparator
function is also now bound by default to the collection — so you
can refer to this within it.

A view's events hash may now also contain direct function
values as well as the string names of existing view methods.

Validation has gotten an overhaul — a model's validate function
will now be run even for silent changes, and you can no longer create
a model in an initially invalid state.

Added shuffle and initial to collections, proxied
from Underscore.

Model#urlRoot may now be defined as a function as well as a
value.

View#attributes may now be defined as a function as well as a
value.

Calling fetch on a collection will now cause all fetched JSON
to be run through the collection's model's parse function, if
one is defined.

You may now tell a router to navigate(fragment, {replace: true}),
which will either use history.replaceState or
location.hash.replace, in order to change the URL without adding
a history entry.

Within a collection's add and remove events, the index
of the model being added or removed is now available as options.index.

Added an undelegateEvents to views, allowing you to manually
remove all configured event delegations.

Although you shouldn't be writing your routes with them in any case —
leading slashes (/) are now stripped from routes.

Calling clone on a model now only passes the attributes
for duplication, not a reference to the model itself.

Calling clear on a model now removes the id attribute.

0.5.3 — August 9, 2011 — Diff — Docs
A View's events property may now be defined as a function, as well
as an object literal, making it easier to programmatically define and inherit
events. groupBy is now proxied from Underscore as a method on Collections.
If the server has already rendered everything on page load, pass
Backbone.history.start({silent: true}) to prevent the initial route
from triggering. Bugfix for pushState with encoded URLs.

0.5.2 — July 26, 2011 — Diff — Docs
The bind function, can now take an optional third argument, to specify
the this of the callback function.
Multiple models with the same id are now allowed in a collection.
Fixed a bug where calling .fetch(jQueryOptions) could cause an
incorrect URL to be serialized.
Fixed a brief extra route fire before redirect, when degrading from
pushState.

0.5.1 — July 5, 2011 — Diff — Docs
Cleanups from the 0.5.0 release, to wit: improved transparent upgrades from
hash-based URLs to pushState, and vice-versa. Fixed inconsistency with
non-modified attributes being passed to Model#initialize. Reverted
a 0.5.0 change that would strip leading hashbangs from routes.
Added contains as an alias for includes.

0.5.0 — July 1, 2011 — Diff — Docs
A large number of tiny tweaks and micro bugfixes, best viewed by looking
at the commit diff.
HTML5 pushState support, enabled by opting-in with:
Backbone.history.start({pushState: true}).
Controller was renamed to Router, for clarity.
Collection#refresh was renamed to Collection#reset to emphasize
its ability to both reset the collection with new models, as well as empty
out the collection when used with no parameters.
saveLocation was replaced with navigate.
RESTful persistence methods (save, fetch, etc.) now return the jQuery deferred
object for further success/error chaining and general convenience.
Improved XSS escaping for Model#escape.
Added a urlRoot option to allow specifying RESTful urls without
the use of a collection.
An error is thrown if Backbone.history.start is called multiple times.
Collection#create now validates before initializing the new model.
view.el can now be a jQuery string lookup.
Backbone Views can now also take an attributes parameter.
Model#defaults can now be a function as well as a literal attributes
object.

0.3.3 — Dec 1, 2010 — Diff — Docs
Backbone.js now supports Zepto, alongside
jQuery, as a framework for DOM manipulation and Ajax support.
Implemented Model#escape, to efficiently handle
attributes intended for HTML interpolation. When trying to persist a model,
failed requests will now trigger an "error" event. The
ubiquitous options argument is now passed as the final argument
to all "change" events.

0.3.1 — Nov 15, 2010 — Diff — Docs
All "add" and "remove" events are now sent through the
model, so that views can listen for them without having to know about the
collection. Added a remove method to Backbone.View.
toJSON is no longer called at all for 'read' and 'delete' requests.
Backbone routes are now able to load empty URL fragments.

0.3.0 — Nov 9, 2010 — Diff — Docs
Backbone now has Controllers and
History, for doing client-side routing based on
URL fragments.
Added emulateHTTP to provide support for legacy servers that don't
do PUT and DELETE.
Added emulateJSON for servers that can't accept application/json
encoded requests.
Added Model#clear, which removes all attributes
from a model.
All Backbone classes may now be seamlessly inherited by CoffeeScript classes.

0.2.0 — Oct 25, 2010 — Diff — Docs
Instead of requiring server responses to be namespaced under a model
key, now you can define your own parse method
to convert responses into attributes for Models and Collections.
The old handleEvents function is now named
delegateEvents, and is automatically
called as part of the View's constructor.
Added a toJSON function to Collections.
Added Underscore's chain to Collections.

0.1.2 — Oct 19, 2010 — Diff — Docs
Added a Model#fetch method for refreshing the
attributes of single model from the server.
An error callback may now be passed to set and save
as an option, which will be invoked if validation fails, overriding the
"error" event.
You can now tell backbone to use the _method hack instead of HTTP
methods by setting Backbone.emulateHTTP = true.
Existing Model and Collection data is no longer sent up unnecessarily with
GET and DELETE requests. Added a rake lint task.
Backbone is now published as an NPM module.