Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7782143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:26:57+00:00 2026-06-01T19:26:57+00:00

I want to override backbone.sync i have already asked this but the problem is

  • 0

I want to override backbone.sync i have already asked this but the problem is i don’t quite get it. I need to know where to put the codes if i were to override the sync function.

If i put it on the model like this

model = Backbone.Model.extend({ sync:"" });

Then how should i call it? if i were to use the save method. Also i need to change the methodMap of create from POST to PUT. temporarily i resorted to this 'create': 'PUT', actually editing the backbone.js file ( iknow its not good ). Before i forgot i also need to add this

sendAuthentication = function (xhr) {
          xhr.setRequestHeader('Authorization', auth)
}; 

As a beforeSend parameter since my server has authentication. Again where should i do it? Where should i go and put the codes? in my model? in my collection? or in my views? Any help? THank you.

update

Also can i override the sync on my collection? i mean can i have something like this?

collection = Backbone.Collection.extend({ sync:""});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:27:00+00:00Added an answer on June 1, 2026 at 7:27 pm

    The strategy behind Backbone framework is to make it simple for editing and flexible for every need. So if you look up the source code you’ll find out that every method, which calls Backbone.sync in fact calls first “this.sync”.

    From the Backbone manual you can read :

    The sync function may be overriden globally as Backbone.sync, or at a
    finer-grained level, by adding a sync function to a Backbone
    collection or to an individual model.

    So you have two options

    Option One – Replacing global Backbone.sync function

    If you override the global Backbone.sync you should place your code in your global application file ( actually anywhere you want, but it must be evaluated ( executed ) at your initial javascript loading, to work as expected

    // Anywhere you want
    
    Backbone.sync = function(method, collection, options) {
            console.log(method, collection options)
    }
    

    This will override Backbone.sync and actually will display on your console what is called every time you call collection.fetch, save, delete, etc.

    Here you have no default Methodmap, infact you have nothing else except the arguments :

    • method – which is a string – ‘read’, ‘create’, ‘delete’, ‘update’
    • collection – which is your collection instance which calls the method
    • options – which has some success, error functions, which you may or may not preserve.

    Debug this in your browser, while reading the Backbone source code, it’s very easy to understand.

    Option Two – Adding to your model/collection sync method

    This is used if you wish to use the default Backbone.sync method for every other model/collection, except the one you specifically define :

    mySocketModel = Backbone.Model.extend({ 
         sync : function(method, collection, options) {
                console.log('socket collection '+this.name+' sync called');
         }
    });
    
    Partners = new mySocketModel({ name : 'partners' });
    Users = new mySocketModel({ name : 'users' });
    Log = new Backbone.Collection;
    

    So if you call Partners.fetch() or Users.fetch(), they won’t call Backbone.sync anymore, but yor Log.fetch() method will.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't want to override Backbone.sync() as some of my models will actually use
I want to override column names in by subclass using xml. i know this
I want to override some config options of Ext.form.NumberField, but I don't find something
I want to override this method for comparing two objects. -(BOOL)isEqual:(id)object Calling function -(void)overridemethod(
I got this class class CWebBrowser2 : public CWnd And i want to override
I do have couple of solutions(rather call them hacks) for doing this but looking
I want to override System menubar controls placed in any desktop window. I have
I want to override the ConfigurationManager.ConnectionStrings.IsReadOnly(); because of which i get the Connectionstring is
I want extend class which have final constructor (in my case it's SimpleXMLElement), but
I want to override access to one variable in a class, but return all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.