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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:58:46+00:00 2026-05-28T01:58:46+00:00

Sorry I couldn’t be anymore specific with the title. I’m building a web-site (personal),

  • 0

Sorry I couldn’t be anymore specific with the title.

I’m building a web-site (personal), which displays different content to the user depending on the query string that is used in the url.

e.g. page=home.html would display home.html

The websites Javascript is wrapped inside an object, with each value containing different data, some pseudo code:

(function(){
    var wrapper = {
        init: function(){
            //Runs on document ready
            this.foo();
            this.nav.render();
        },
        foo: function(){
            //Some functionality goes here for the website, e.g. Display something from an API
        },
        nav: {
            //Functionality to handle the navigation, has different properties
            config: {
                //Contains the config for nav, e.g. page names + locations
                dir: '/directory/to/content/',
                pages: {
                    page_name: wrapper.nav.config.dir + 'page_value'
                }
            },
            render: function(){
                 //some code
            },
            routes: function(){
                 //some code}
            }
        }
    };

    $(function(){
        wrapper.init();
    });
})();

My problem is that I’m trying to prepend the dir value to each of the page values (inside the object where the pages are defined), expecting to get the output of (in this pseudo code case) of directory/to/content/page_value, but instead dir is undefined when I’m trying to access it, I’ve tried the following to achieve what I want:

  • wrapper.nav.config.dir + ‘page_value’

I’ve been playing around with the last 30 minutes trying to find out what I’m doing wrong, and even thought about hard-coding the URL in for each page.

The reasoning for wanting to do this is that my local development server and web host have different directory structures, so I don’t want to re-write the URL’s each time I want to develop + publish. As for why everything is wrapped inside an object, I thought it would be easier to maintain this way.

Hopefully the answer is simple and it’s just an amateur mistake / lack of 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-05-28T01:58:46+00:00Added an answer on May 28, 2026 at 1:58 am

    The issue is that you can’t refer to a variable that is being defined in that very definition.

    So, inside the definition of wrapper, you can’t refer to wrapper. And, inside the definition of config, you can’t refer to config either and so on.

    The usual design pattern for solving this is to initialize as much as you can in the declaration of your data structure and then do the rest in .init() when you can freely access all of it.

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

Sidebar

Related Questions

Sorry about the title, I couldn't think of a better way to describe the
Sorry for the title, I couldn't argue something better. Here is my question: Is
Sorry, poorly descripted title and couldn't think of how to phrase it. Working on
Sorry for dodgy title, couldn't think of anything better... Anyway, I have written a
Sorry for the awful title, I couldn't think of anything better. Basically I have
Sorry couldn't think of a better title. :) Here goes, I have been pulling
Sorry I couldn't come up with a better title. Here is my htaccess RewriteEngine
Sorry I couldn't think of a better title... So I have this database where
Sorry, I couldn't provide a better title for my problem as I am quite
Sorry about the title, couldn't really think of anything else to describe the problem

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.