When we talk about attributes in Backbone, they often sound similar to regular JavaScript properties. After all, both attributes and properties are key-value pairs stored on a Model
object. The difference between the two is that attributes aren't (in a technical sense) actually properties of a Model at all; instead, they are the properties of a property of a Model
. Each Model
class has a property called attributes
, and the attributes themselves are stored as properties of that attributes
property. Take an example of the following code snippet:
var book = new Backbone.Model({pages: 200}); book.renderBlackAndWhite = true; book.renderBlackAndWhite // is a property of book book.attributes.pages; // is an attribute of book book.attributes.currentPage = 1; // is also an attribute of book}