A Simple Backbone.js View

This is our html which includes a template within script tags.

This is our backbone code.

View this example on JSFilddle

A Simple Backbone.js Model

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

// 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

Related Articles

© 2018 Aldomatic

Theme by Anders NorenUp ↑