Notes on Backbone.js
Jan. 1st, 2015 01:28 pmBackbone.js: one of a bunch of MVC-ish frameworks. Others include Angular, Spine, JavaScript MVC, Ember, Knockout.
TodoMVC is a to-do list app built in several different frameworks so you can compare them.
Backbone provides:
Models: represent domain objects.
Wine = Backbone.Model.extend(); // Creates a model w = new Wine({prop1: val1, prop2: val2, ...}) w.toJSON()Collections: a bunch of Model objects. Will apparently infer a REST-ish backend automatically.
WineList = Backbone.Collection.extend({ Model: Wine, url: "http:..." // URL for the REST back-end }) wines = new WineList([list of objects used to create Wine instances]); wines.each(function (w) {...})Views:
HomeView = Backbone.View.extend(); view = new HomeView(); view.render()
Templates: Backbone uses Underscore for templating by default.
Routes: recording app state in the URL, and moving between different states.
wineApp = new AppRouter(); wineApp.routes = dict of string to method name
Events:
View.events = dict of event name to method name called when event is triggered.