model.hasChanged

hasChangedmodel.hasChanged([attribute]) Has the model changed since its last set? If an attribute is passed, returns true if that specific attribute has changed. Note that this method, and the following change-related ones, are only useful during the course of a "change" event. book.on("change", function() { if (book.hasChanged("title")) { ... } });

model.has

hasmodel.has(attribute) Returns true if the attribute is set to a non-null or non-undefined value. if (note.has("title")) { ... }

model.get

getmodel.get(attribute) Get the current value of an attribute from the model. For example: note.get("title")

model.fetch

fetchmodel.fetch([options]) Merges the model's state with attributes fetched from the server by delegating to Backbone.sync. Returns a jqXHR. Useful if the model has never been populated with data, or if you'd like to ensure that you have the latest server state. Triggers a "change" event if the server's state differs from the current attributes. fetch accepts success and error callbacks in the options hash, which are both passed (model, response, options) as arguments. // Poll every 10 sec

Model.extend

extendBackbone.Model.extend(properties, [classProperties]) To create a Model class of your own, you extend Backbone.Model and provide instance properties, as well as optional classProperties to be attached directly to the constructor function. extend correctly sets up the prototype chain, so subclasses created with extend can be further extended and subclassed as far as you like. var Note = Backbone.Model.extend({ initialize: function() { ... }, author: function() { ... }, coordi

model.escape

escapemodel.escape(attribute) Similar to get, but returns the HTML-escaped version of a model's attribute. If you're interpolating data from the model into HTML, using escape to retrieve attributes will prevent XSS attacks. var hacker = new Backbone.Model({ name: "<script>alert('xss')</script>" }); alert(hacker.escape('name'));

model.destroy

destroymodel.destroy([options]) Destroys the model on the server by delegating an HTTP DELETE request to Backbone.sync. Returns a jqXHR object, or false if the model isNew. Accepts success and error callbacks in the options hash, which will be passed (model, response, options). Triggers a "destroy" event on the model, which will bubble up through any collections that contain it, a "request" event as it begins the Ajax request to the server, and a "sync" event, after the server has successfull

model.defaults

defaultsmodel.defaults or model.defaults() The defaults hash (or function) can be used to specify the default attributes for your model. When creating an instance of the model, any unspecified attributes will be set to their default value. var Meal = Backbone.Model.extend({ defaults: { "appetizer": "caesar salad", "entree": "ravioli", "dessert": "cheesecake" } }); alert("Dessert will be " + (new Meal).get('dessert')); Remember that in JavaScript, objects are passe

model.clone

clonemodel.clone() Returns a new instance of the model with identical attributes.

model.clear

clearmodel.clear([options]) Removes all attributes from the model, including the id attribute. Fires a "change" event unless silent is passed as an option.