Backbone.js
Overview
Backbone.js is a small, unopinionated library that adds structure to JavaScript-heavy web apps with key-value-bound Models, ordered Collections, event-driven Views, and a Router, all connecting to an existing API over a RESTful JSON interface. Its only hard dependency is Underscore.js; jQuery (or Zepto) is used for DOM and Ajax. Read this when maintaining or extending a Backbone codebase, debugging model/view event wiring, or syncing data with a REST backend.
Official sources
Install / setup
npm install backbone underscore jquery
Backbone's only hard dependency is Underscore.js (>= 1.8.3); jQuery (>= 1.11.0) is needed for Backbone.View DOM work and Backbone.sync (https://backbonejs.org/#Getting-started). You can also drop in backbone-min.js via a script tag from backbonejs.org.
Core concepts
- Model — key-value data with validation, defaults, and
change events via get/set.
- Collection — ordered set of models with Underscore enumerable methods and
add/remove/reset events.
- View — binds a DOM
el to model/collection data, declares an events hash, and renders.
- Events — mixin (
on/off/trigger, listenTo) usable on any object; foundation of all reactivity.
- Router — maps URL fragments to handlers using hashchange or History
pushState.
- Backbone.sync — default persistence layer mapping CRUD to RESTful JSON (override for custom backends).
- Backbone.history — singleton started with
Backbone.history.start() to begin route monitoring.
- extend — class-style inheritance helper (
Backbone.Model.extend({...})) for all components.
Best practices
Common pitfalls
- Re-binding handlers with
on on re-render leaks listeners → use listenTo and call remove()/stopListening on teardown.
- Routes never fire because
Backbone.history.start() was not called → start history after routers are constructed.
- Expecting reactive templates → Backbone does not auto-render; call
render() from a change listener yourself.
Examples
var Todo = Backbone.Model.extend({ defaults: { done: false } });
var TodoView = Backbone.View.extend({
tagName: 'li',
events: { 'click .toggle': 'toggle' },
initialize: function () {
this.listenTo(this.model, 'change', this.render);
},
toggle: function () {
this.model.set('done', !this.model.get('done'));
},
render: function () {
this.$el.text(this.model.get('title'));
return this;
}
});
var view = new TodoView({ model: new Todo({ title: 'Learn Backbone' }) });
$('#list').append(view.render().el);
Further reading
Related skills
- ../jquery — DOM/Ajax layer Backbone relies on for views and sync
- ../react — modern component framework that superseded Backbone-era MVC
- ../ember — opinionated SPA framework contrast to Backbone's minimalism
1---2name: backbone3description: Backbone.js — a minimalist JavaScript MVC-ish library that gives web apps structure via Models, Collections, Views, Events, and a hash/pushState Router over a RESTful JSON API. Consult when working in a legacy or lightweight Backbone codebase, wiring model change events to view re-renders, syncing models/collections to a REST backend, defining client-side routes, or integrating with Underscore/jQuery and patterns like Marionette.4domain: stack5category: frontend6tags: [backbone, backbonejs, mvc, underscore, jquery, frontend, javascript]7official_sources:8 - https://backbonejs.org/9 - https://github.com/jashkenas/backbone10 - https://www.npmjs.com/package/backbone11verified: 2026-06-1712metadata:13 source: https://skillmd.com/skills/gabriel7silva/backbone14---1516# Backbone.js1718## Overview19Backbone.js is a small, unopinionated library that adds structure to JavaScript-heavy web apps with key-value-bound Models, ordered Collections, event-driven Views, and a Router, all connecting to an existing API over a RESTful JSON interface. Its only hard dependency is Underscore.js; jQuery (or Zepto) is used for DOM and Ajax. Read this when maintaining or extending a Backbone codebase, debugging model/view event wiring, or syncing data with a REST backend.2021## Official sources22- Docs: https://backbonejs.org/23- Repo: https://github.com/jashkenas/backbone24- Install: https://www.npmjs.com/package/backbone2526## Install / setup27```bash28npm install backbone underscore jquery29```30Backbone's only hard dependency is Underscore.js (>= 1.8.3); jQuery (>= 1.11.0) is needed for `Backbone.View` DOM work and `Backbone.sync` (https://backbonejs.org/#Getting-started). You can also drop in `backbone-min.js` via a script tag from backbonejs.org.3132## Core concepts33- **Model** — key-value data with validation, defaults, and `change` events via `get`/`set`.34- **Collection** — ordered set of models with Underscore enumerable methods and `add`/`remove`/`reset` events.35- **View** — binds a DOM `el` to model/collection data, declares an `events` hash, and `render`s.36- **Events** — mixin (`on`/`off`/`trigger`, `listenTo`) usable on any object; foundation of all reactivity.37- **Router** — maps URL fragments to handlers using hashchange or History `pushState`.38- **Backbone.sync** — default persistence layer mapping CRUD to RESTful JSON (override for custom backends).39- **Backbone.history** — singleton started with `Backbone.history.start()` to begin route monitoring.40- **extend** — class-style inheritance helper (`Backbone.Model.extend({...})`) for all components.4142## Best practices43- Use `listenTo`/`stopListening` instead of `on` so views unbind cleanly and avoid leaks (https://backbonejs.org/#Events-listenTo).44- Keep view-managed DOM scoped to `this.$el` / the `events` hash rather than global selectors (https://backbonejs.org/#View-delegateEvents).45- Define `model` on Collections and `url`/`urlRoot` so `fetch`/`save` hit the right REST endpoint (https://backbonejs.org/#Collection-url).46- Implement `validate` and listen for `invalid` to reject bad `set`/`save` calls (https://backbonejs.org/#Model-validate).4748## Common pitfalls49- Re-binding handlers with `on` on re-render leaks listeners → use `listenTo` and call `remove()`/`stopListening` on teardown.50- Routes never fire because `Backbone.history.start()` was not called → start history after routers are constructed.51- Expecting reactive templates → Backbone does not auto-render; call `render()` from a `change` listener yourself.5253## Examples54```javascript55var Todo = Backbone.Model.extend({ defaults: { done: false } });5657var TodoView = Backbone.View.extend({58 tagName: 'li',59 events: { 'click .toggle': 'toggle' },60 initialize: function () {61 this.listenTo(this.model, 'change', this.render);62 },63 toggle: function () {64 this.model.set('done', !this.model.get('done'));65 },66 render: function () {67 this.$el.text(this.model.get('title'));68 return this;69 }70});7172var view = new TodoView({ model: new Todo({ title: 'Learn Backbone' }) });73$('#list').append(view.render().el);74```7576## Further reading77- https://backbonejs.org/#FAQ — official FAQ and design rationale78- https://backbonejs.org/examples/todos/ — the canonical TodoMVC-style example79- https://marionettejs.com/ — Marionette, a higher-level framework built on Backbone8081## Related skills82- ../jquery — DOM/Ajax layer Backbone relies on for views and sync83- ../react — modern component framework that superseded Backbone-era MVC84- ../ember — opinionated SPA framework contrast to Backbone's minimalism