backbone.js Extending models


Example

var Vehicle = Backbone.Model.extend({
  
  description: function () {
    return 'I have ' + this.get('wheels') + ' wheels';
  }
  
});

var Bicycle = Vehicle.extend({
  
  defaults: {
    wheels: 2
  }
  
});

var Car = Vehicle.extend({
  
  defaults: {
    wheels: 4
  }
  
});

var bike = new Bicycle();
bike.description() // I have 2 wheels;

var car = new Car();
car.description() // I have 4 wheels;;