Skip to content

Instantly share code, notes, and snippets.

@mallim
Created October 18, 2013 06:53
Show Gist options
  • Save mallim/7037481 to your computer and use it in GitHub Desktop.
Save mallim/7037481 to your computer and use it in GitHub Desktop.
Example showing how to override Backbone Model sync method (specific to a model)
var MyModelOverrideLocal = Backbone.Model.extend({
sync: function (method, model, options) {
if ( method === 'delete' ) {
if ( options.data ) {
// properly formats data for back-end to parse
options.data = JSON.stringify(options.data);
}
// transform all delete requests to application/json
options.contentType = 'applicaton/json';
}
if (method === 'read') {
// Do something
}
if( method === 'create'){
// Do something
}
if( method === 'update'){
// Do something
}
Backbone.apply(this, [method, model, options]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment