Categories
backbonejs javascript

A Simple Backbone.js Model

I have been reintroducing myself to Backbone.js and I thought I would post small snippets for reference.

[code lang=”js” autolinks=”false” classname=”codeClass” collapse=”false” firstline=”1″ gutter=”true” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″]

// Bare model
var Person = Backbone.Model.extend({});

// Model with some default values
var Person = Backbone.Model.extend({
defaults: {
name: "unknown",
drinks: "water"
}
});

// Model with some an initialize function
var Person = Backbone.Model.extend({
initialize: function(){
// This will be called every time a Person instance is made
}
});

// instantiate a new person and pass in some properties
var ghost4hire = new Person({name: "Joe Padilla", drinks: "Beer" });

// set a property
ghost4hire.set({twitter: "@ghost4hire"});

// get a property
ghost4hire.get("name");

[/code]

Related Articles

Some males gain harder erection, but unable to maintain harder erection due levitra ordering to improper blood supply to the penile region. The time saved buy viagra by avoiding long lines at the prescription counter at the local drugstore for collection of the medication. Jaiphal or nutmeg offers effective cure for depression, irritability and sleeplessness. my review here purchase viagra online Erectile brokenness is a sexual issue that inconveniences the men sales viagra on sale at pharmacy a great deal.