Skip to content

Instantly share code, notes, and snippets.

@marka2g
Created March 29, 2012 03:07
Show Gist options
  • Save marka2g/2232841 to your computer and use it in GitHub Desktop.
Save marka2g/2232841 to your computer and use it in GitHub Desktop.
CodeSchool Ch2
//1. Defaults
var Appointment = Backbone.Model.extend({
defaults: {
title: 'Checkup',
date: new Date()
}
});
//2 Fixing Defutls
var Appointment = Backbone.Model.extend({
defaults: function(){
return {
title: 'Checkup',
date: new Date()
}
}
});
//3. Fetch Url
var Appointment = Backbone.Model.extend({urlRoot:'/appointments'});
var apt = new Appointment({id:1});
apt.fetch();
//4. Syncing Changs
var appointment = new Appointment({id: 1});
appointment.set({cancelled:true});
appointment.save();
//5. Listening for Changes
var appointment = new Appointment({id: 1})
appointment.on('change', function(){
alert('change happened');
});
//6. Less listening
appointment.on('change:cancelled', function(){
alert('appointment canceled');
});
// toJSON method - getting it all
var appointment = new Appointment({id: 1});
console.log(appointment.toJSON());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment