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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:33:20+00:00 2026-06-12T22:33:20+00:00

I was examining various JavaScript libraries for learning purposes. Basically I want to find

  • 0

I was examining various JavaScript libraries for learning purposes. Basically I want to find the best way to initiliaze a namespace and see how pros load up all the associated files in their libraries. I came across this a few times in the main file (for example lets call it myNameSpace.js) that the library user would call in a few libraries:

(function() {

    var jsFiles = window.MyNameSpace;

    window.MyNameSpace = {
        _getScriptLocation: (function() { 
            /* some code here */ 
        })
    };

    if(!jsFiles) { 
        jsFiles = [/* An array of ALL the library files! */];
    }

    for(var i=0, len = jsFiles.length; i<len; i++) { 
        scriptTags[i] = "<script src='" + jsFiles[i]  + "'></script>"; 
    }

    if(scriptTags.length > 0) { 
        document.write(scriptTags.join("")); 
    }

})();

So, with this setup, if the library user wanted to include only certain portions of the library, they would specify before loading the myNameSpace.js by doing something along the lines of:

<script type='text/javascript'> window.MyNameSpace = ["libraryFile1.js", "libraryFile2.js", "libraryFile3.js"]</script>
<script type='text/javascript' src="MyNameSpace.js"></script>

My question is, window.MyNameSpace is an object and if the script assigns jsFiles to an array setup as window.MyNameSpace, this is going to be an assignment by reference, correct? But immediately after that line, window.MyNameSpace gets completely changed. So shouldn’t jsFiles no longer reference the original array that was passed in? What am I missing here in my understanding?

  • 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-12T22:33:22+00:00Added an answer on June 12, 2026 at 10:33 pm

    JS does not assign “by reference”, assignment is copying, but when we assign objects, we copy their addresses, not objects “themselves”.

    Look

    window.MyNameSpace = ["libraryFile1.js", "libraryFile2.js", "libraryFile3.js"]
    

    window.MyNameSpace point to some object in memory. Let’s assume its address is 0x12345

    var jsFiles = window.MyNameSpace;
    

    jsFiles now points to the same object (0x12345)

    window.MyNameSpace = {...}
    

    window.MyNameSpace now points to some other object (let it be 0x56789), but jsFiles still points to the first object (0x12345).

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

Sidebar

Related Questions

Examining the compiled code of the sinf() on our GCC implementation, I see that
Examining the attributes of UTF-16 and UTF-8, I can't find any reason to prefer
After examining the jQuery source, I see that the problem I am having is
I am examining the private c++ function hooking code snippet from mobilesubstrate and see
I am trying to teach myself the Google Closure javascript library. I am examining
Without examining each method, how can I find duplicate methods in a class? Duplicate
I'm examining the source of the built-in .net control for TabControl, and I see
I'm examining someone else's code and I'm trying to find out what functions are
Using T4 I want to generate some code based on examining what files are
Examining Zend Framework, I found that all setter methods (of those I’ve examined) return

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.