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 8277843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:48:41+00:00 2026-06-08T08:48:41+00:00

I am doing something like this in my code: data_hash = {}; data_hash[‘some_model_key’] =

  • 0

I am doing something like this in my code:

data_hash = {};
data_hash['some_model_key'] = 'A';
console.log(data_hash['some_model_key']); /* prints A */
model.save(data_hash,{
    wait:true,
    success:function(){
        console.log(data_hash['some_model_key']); /* prints B */
    }
});                  

I understand that if the server changes the state of the model and i am setting wait:true then my backbone model should receive the new value. But why is my attribute hash being changed?

  • 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-08T08:48:42+00:00Added an answer on June 8, 2026 at 8:48 am

    Why Backbone changes your object

    If you take a look at the annotated source code, you’ll notice that in case of a wait:true option, the success callback extends the attr object with the server attributes.

        if (options.wait) {
          delete options.wait;
          serverAttrs = _.extend(attrs || {}, serverAttrs);
        }
    

    And according to Underscore doc, _.extend copies all of the properties in the source objects over to the destination object, overriding any previously defined property. Why it is the chosen behavior is a guess, but I suspect it is to keep all references in sync with the “real” state of the model. Or it’s an unforeseen side effect.

    Note that the first object you pass to model.save is expected to be attributes you want to set on your model as part of the save process. From Backbone doc

    save model.save([attributes], [options])
    The attributes hash (as in set) should contain the attributes you’d
    like to change — keys that aren’t mentioned won’t be altered — but, a
    complete representation of the resource will be sent to the server.

    What you can do to keep your object untouched

    Pass a clone of your object to model.save:

    model.save(_.clone(data_hash), ...)
    

    Note: you don’t need to have a wait:true option for your model to receive the values from your server, model.set will be always be called with the new values.

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

Sidebar

Related Questions

Am I doing something wrong if I need code like this in a Controller?
I am doing something like this in myproject.myapp.urls : from django.conf.urls.defaults import * urlpatterns
I am talking about doing something like this: LOCK TABLE page WRITE; SELECT *
I am currently doing something like this: myFunc(tracer); function tracer(message:String):void{ trace(message); } function myFunc(callback:Function):void{
I am doing something like this- http://www.w3schools.com/html5/tryit.asp?filename=tryhtml5_video_js_prop but I want to replace the buttons
I am doing something like this in SP, insert into @FilteredTbl select * from
I can deny a specific user DB viewing by doing something like this: DENY
So, I was thinking of doing something like this: zones#show /map/map_id/zones/zone_id And this: zones#index
i've one text file, and im doing something like this : resultingTokens = currentLine.split(\\t);
I'm doing some analysis something like this: library(plyr) input.files <- c(file1.txt, file2.txt, file3.txt) input.data

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.