in as little or as much as you like Some needed structure to mountains of JS Very agnostic about DOM util libs, template libs, code patterns Backbone != jQuery Examples of using it big players
}, initialize: function() { // runs when model constructed }, validate: function(attrs) { if (attrs.inStock === false) return 'No can do buddy-ro!' if (attrs.price <= 0) return "We're not running a charity here." } }); var fiftyShadesOfJavascript = new Book({ price: 14.99, title: '50 Shades of Javascript' }); fiftyShadesOfJavascript.set('price', -5); // validation error
}); var library = new BookCollection(); library.on('add', function(book) { var bookview = new BookView({ model: book }); $('.content').append(bookview.render().$el); }); library.add(fiftyShadesOfJavascript);
{ if (this.id) return '/books/' + this.id; // HTTP PUT return '/books/'; // HTTP POST } }); var fifty = new Book({ price: 14.99, title: '50 Shades of Javascript' }); fifty.set('title', '50 Shades: Improved With 1 More Shade!'); fifty.save(); // triggers ajax POST to model.url()