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

The Archive Base Latest Questions

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

I couldn’t really word the question less vaguely, but I think you will understand…

  • 0

I couldn’t really word the question less vaguely, but I think you will understand…

I am developing a game engine in Javascript, and the Scene object, which is a container of many things, has a method that is supposed to change one array in it, specifically the one holding all the things that can be drawn.

This array is accessed like this:

scene.internals.draw

The problem is, it is referenced many times in the method, and I think that the name/path might change. Naturally, I don’t want to change every reference to it in the method each time I change the the array’s path, so I did this:

var location = scene.internals.draw;

Now, the actual method code and the algorithm can stay intact, and if the name/path of the array in the scene changes, I only need to change that one line.

And it works pretty well for the most part. I can .push(obj) to it, etc, but at one point, I need to “disect” the array, ie, split it in half, add something, and then put it back together, like this:

buff1 = location.slice(0, i); //First slice of the array.
buff2 = location.slice(i, location.length); //Second slice of the array.

//Add something in between those slices.
buff1.push(ob);
location = buff1.concat(buff2); //Problems here!

This worked well while location was just scene.internals.draw, as it changed the array directly. But now, I assign the new value to the local location variable, not the desired scene.internals.draw one!

Question: how can I, using the = operator, assign values to “real” objects, instead of the variables that contain references to these objects (like location)?

The obvious solution would be this, at the end of the method:

scene.internals.draw = location.slice();

This is OK, the only side effect is that I will have to write the original name twice, and edit it twice, which isn’t such a big issue. But, I maybe find myself in other situations where I just might need that functionality, so I’d still like an answer.

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

    There is no assignment by reference in javascript, so you cannot do this. What you are doing is usually mistaken for assignment by reference but it is in fact a copy of a reference value which has implications like this.

    You probably have a deeper problem somewhere since you are doing this but I don’t wanna get into that.

    You could do this:

    location.splice( 0, location.length ); //Remove all items in the array
    location.push.apply( location, buff1.concat(buff2) ); //Push the buffers into the array
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Couldn't think of a more appropriate question title, but I'm looking for some advice
I couldn't really come up with a proper title for my question but allow
Couldn't think of better phrasing for this question, but basically I want to store
I couldn't think of a way to word the title, so sorry for that,
Couldn't figure out how to word the question accurately, so here's an example: Given
Couldn't find an answer to this question. It must be obvious, but still. I
Couldn't really find it, but probably it's me not knowing how to search properly
(Couldn't think of any simpler way to write the title for this, but the
I couldn't find anything on this, but probably its just because I don't know
I couldn't find a straight answer to my question and need to know it

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.