Search code examples
javascriptbackbone.jsprototypefetch

Backbone - overriding sync using Prototype not assigning values


I am very new to backbone.js and was trying to add custom headers by overriding sync method.

(function(sync){
Backbone.Model.prototype.sync = function(method, model, options) {
    return sync(method, model, $.extend(true, {
        headers: //custom header here
    }, options));
};})(Backbone.Model.prototype.sync);

This seems to be only working when I remove the Model.Prototype. Can someone please explain why I am not able to override the prototype method here?


Solution

  • Instead of sync() try sync.call(this, arguments)