Created
March 29, 2012 03:07
-
-
Save marka2g/2232841 to your computer and use it in GitHub Desktop.
CodeSchool Ch2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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