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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:40:31+00:00 2026-06-13T17:40:31+00:00

I have a script with the following structure: Test = { CONSTANTS : {},

  • 0

I have a script with the following structure:

Test = {

    CONSTANTS : {},
    VARIABLES : {},
    MARKUP : {},
    FUNCTIONS : {
        init : function () {

            // Access variable from different namespace
            var all_constants = DifferentNamespace.CONSTANTS; // WORKS
            var tester = DifferentNamespace.CONSTANTS.chunk_of_markup; // SAYS UNDEFINED
        }
    },
    init : function () {

        // Call real init() function

        $(document).ready(function () {

            Test.FUNCTIONS.init();
        });
    }

};

$(document).ready(function () {

    Test.init();
});

If I remove either of the $(document).ready(..) function calls, when I try to access a constant from a different namespace it is undefined; with both is works well.

As you can see I’m using two init() functions, one it just to neaten up the call to init because I have wrapped functions inside an additional object.

If I remove the function that is on the same level as CONSTANTS, VARIABLES etc and try to call the init() within Test.FUNCTIONS it still does not work.

Edit:

If i console.log(all_constants) I get the full object (with .chunk_of_markup) but if I console.log(tester) is get undefined. If i wrap tester i get []

I should also note that the other namespace gets the markup from a seperate file.

Any ideas why?

  • 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-13T17:40:33+00:00Added an answer on June 13, 2026 at 5:40 pm

    Having two document ready doesn’t make a difference here. You could have one document.ready and/or call Test.FUNCTIONS.init directly and all should work, and the fact that they are in different namespaces doesn’t matter as well.

    As for why you’re getting undefined, I think it is probably because your chunk_of_markup variable is actually undefined at that point. My guess is that you’re getting the value for it through AJAX and so the call is done asynchronously which means the DOM will be ready before it actually returns a value. When you use the Debugger then the value is evaluated at the point of time where you run the command so by then, the async call already returns successfully (it’s a race condition, if you’re fast enough and your AJAX is slow then you can still get undefined, and it’s also why 2 ready functions happen to make it slow enough for the AJAX call to return but it’s still unreliable).

    In all cases, if my theory is correct, then you need to hook to the callback of the AJAX request rather that DOM ready event, this is the only place where you can guarantee that your variable is defined.

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

Sidebar

Related Questions

Trying to get a simple test perl script working. Have the following files/folder structure
I have the following directory structure : /script/x.js /includes/x.txt /1/2/index.html After hooking a webpage
I have the following HTML structure: $('#subgroup a').nextUntil('h3').wrapAll('<div></div>'); <script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js></script> <div id=subgroup> <h3>Group name
I have the following script: (function($) { $.fn.easyPaginate = function(options){ var defaults = {
I have the following script: Timer=0; function countdown(auctionid){ var auctions; var divs; Timer=Timer+1; if((Timer%10==0)||(Timer==1)){
I have the following script select c.id from .TBL_COUPONS. as c inner join .TBL_BUSINESS.
I have the following html structure. <ul> <script id=agendaTmpl type=text/x-jquery-tmpl> <li class=arrow boundElement style=height:40px;
Suppose I have the following directory structure: C:\Test C:\Test\2009 C:\Test\2009\files\Artists C:\Test\2009\files\Artists\SnoopDog C:\Test\2009\files\Artists\SnoopDog\albums.txt C:\Test\2009\files\Artists\SnoopDog\albums.jpg C:\Test\2009\files\Artists\SnoopDog\hobbies.doc
I have the following scenario- Pig version used 0.70 Sample HDFS directory structure: /user/training/test/20100810/<data
I have a script of the following structure: SELECT SUM(CASE WHEN pf.info IS NOT

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.