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

  • Home
  • SEARCH
  • 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 7956529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:01:08+00:00 2026-06-04T04:01:08+00:00

Looking at the following code, can someone explain how values are passed around in

  • 0

Looking at the following code, can someone explain how values are passed around in JavaScript.

function loadImages() {
  for(var sec in images) {
    theme = images[sec];
      for(var tsec in theme) {
        theme[tsec].img = new Image();
        theme[tsec].img.src = 'images/'+theme[tsec].src+'.png';
      }
  }
}

Then in another functions:

function definitionToSpriteDataMapping() {
  var result = {};
  for(var definition in blocks) {
    var sprite = blocks[definition].sprite;
    for(var secnm in images) {
      section = images[secnm];
      for(var spritenm in section) {
        if(sprite == spritenm) {
          result[definition] = {};
          result[definition].img = section.img;
        }
      }
    }
  }
  return result;
}

I cut out some code for simplicity sake but its still quite convoluted. Basically there are 2 objects (images & blocks) which are nested key:value pairs. In the first block of code

theme = images[sec]; 
theme[tsec].img.src = 'images/'+theme[tsec].src+'.png';

In the second line of code there is

section = images[secnm];
result[definition] = {};
result[definition].img = section.img;

There is no .img in “images” before the first block of code where .img is added to “theme”. But this seems to be reflected back into “images” as seen in the second block of code. Are all objects like pointers in JavaScript? Will “result” have the same relationship with “blocks” as “theme” has with “images”? What if I remove an element from “theme”, will that be reflected in “images”?

  • 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-04T04:01:11+00:00Added an answer on June 4, 2026 at 4:01 am

    Using theme = images[sec] you will indeed create a pointer to that object in memory. So adding img to theme object will as well add img to that image, as they are the same object. So yes, the same goes for result.
    Altering, adding or removing properties of an object referenced in such a way will influence the actual object. The same goes for arrays.

    If you don’t like that behavior, you should clone the object. You can clone a simple object simply by copying all properties:

    var original = { name: "James", age: 73, male: true };
    var clone = { };
    for( var k in original )
        clone[ k ] = original[ k ];
    

    But if any property of that original is an array or object itself, it will be a reference. If you don’t have any objects or arrays as properties, the above snippet will do fine. Otherwise you should write a clone function and recursively clone every member of the original.

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

Sidebar

Related Questions

Please can someone advise me why the following code appears to work fine in
I was looking at the following code I came across for printing a string
I was looking at the following code in python: for ob in [ob for
I'm looking for the Go equivalent of scanf(). I tried with following code: 1
I am looking to do some method chaining. I have the following code: class
I am looking at some code (Delphi 7) with following check is at the
I'm looking at some legacy code which has the following idiom: Map<String, Boolean> myMap
I am looking for a nice code solution for the following problem. I have
i am looking at some ancient code and there is the following line of
Please can someone help me out with the expression required for the following: A

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.