1

I am attempting to override a models save method and set an error callback. I am using a mixture of localStorage and server side data so in the event that the app can't connect to the server, I want to save the model to local storage. Here is my model code:

var Project = Backbone.Model.extend({
        urlRoot: Settings.urls.projects.project,

        save: function(attributes, options){
            options || (options = {});

            this.set("last_updated", new Date().toISOString(), {silent: true});

            options.error = function(){
                console.log("Error callback");
            }

            return this.constructor.__super__.save.apply(this, arguments);
        },

As you can see, I am attempting to set options.error within the save method and then call the super method to actually action the save. For some reason it is ignoring the function and the console log statement is not getting called. Anyone have any ideas?

Hanpan
  • 10,013
  • 25
  • 77
  • 115
  • Are you certain that spreading the `arguments` -object works? Try adding a success callback, so you'll know if it works or not. – jakee Aug 23 '12 at 05:59
  • Open your local version of `backbone.js` and put some `console.log` in the [Model.save()](https://github.com/documentcloud/backbone/blob/master/backbone.js#L348) to see what is arriving there. – fguillen Aug 23 '12 at 11:10
  • Also check the other ways to call [Backbone super()](http://stackoverflow.com/questions/8596861/super-in-backbone) – fguillen Aug 23 '12 at 11:13

1 Answers1

1

Check this reference: http://backbonejs.org/#Model-extend

You need to do something like this:

return Backbone.Model.prototype.save.call(this, attributes, options);
Daniel Aranda
  • 6,426
  • 2
  • 21
  • 28