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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:28:50+00:00 2026-06-17T23:28:50+00:00

I would like to understand well something i observe more and more. In some

  • 0

I would like to understand well something i observe more and more.

In some circonstances, different instances from a same model change their attributes the same way (if i have 2 UserModel A and B, if i change A, B will be affected the same way).

I observed some practical cases:

When i send an instance of a model to a view constructor, they are linked, if i change the model in my view, the outside one will be affected the same way. I guess sometime we just send a pointer and not a copy of the instance to the view.

More specific with some code;

A = new UserModel();
B = new UserModel();

var Data = A.get('info'); //where info = {some: "thing"};
Data.some = 'other';
B.set('info', Data); //A.get('info') == B.get('info')

Because i got the object info and not only the attributes separately (i tested it and there is no repercution between the values this way).

So my question is, are we always using pointers with objects in javascript ? Is it specific to backbone ? I would like to understand what is behind this behavior.

Thanks.

  • 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-17T23:28:52+00:00Added an answer on June 17, 2026 at 11:28 pm

    Objects and Arrays are passed or assigned as references in javascript, not copies. If you want a copy of an object or an array, you have to explicity make a copy.

    Simpler types such as numbers, boolean are copied when assigned or passed.

    Strings are a bit of special case. They are passed as references, but since strings are immutable (can’t be changed), you can’t really use a string reference for anything because any attempt to modify the string creates a new string.

    A couple examples:

    // arrays assigned by reference
    var a = [1,2,3];
    var b = a;
    a[0] = 0;
    alert(b[0]);  // alerts 0 because b and a are the same array
    
    // objects assigned by reference
    var c = {greeting: "hello"};
    var d = c;
    c.greeting = "bye";
    alert(d.greeting);   // alerts "bye" because c and d are the same object
    
    // numbers assigned as copies
    var e = 3.414;
    var f = e;
    e = 999;
    alert(f);    // alerts 3.414 because f is its own copy of the original number
    
    // make a copy of an array
    var g = [1,2,3];
    var h = g.slice(0);    // h is now a copy
    h[0] = 9;
    alert(g);              // shows [1,2,3]
    alert(h);              // shows [9,2,3]
    

    The same is true for passing arguments to a function or returning values from a function. Unless an explicit copy is created, arrays and objects are passed or returned by reference.


    A shallow copy of an array can be made with the .slice() method.

    var arr1 = [1,2,3];
    var arr2 = arr1.slice(0);   // make independent copy of first array
    

    A shallow copy of an object can be made by copying each property from the original object to a new object.

    Deep copies involve testing the type of each item being copied and recursing on the object if it is an object or array so nested objects and arrays are copied too.

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

Sidebar

Related Questions

I am new to silver light and would like to understand a bit more
I would like to extract some text from an html file using Regex. I
I would like to understand what Implement Interface Explicitly entails in C# based on
I would like to understand whats the best way to handle exceptions in Multicast
I would like to understand how Etherpad's timeline feature work. If you don't know
I would like to understand that what is Mesh Object and its conection with
I would like to understand what class << self stands for in the next
I would like to understand how object deletion works on python. Here is a
I am developing a Rails application and would like to understand when to use
I'm new to the subject of encoding and would like to understand it in

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.