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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:45:52+00:00 2026-05-14T16:45:52+00:00

I am now in the process of removing most globals from my code by

  • 0

I am now in the process of removing most globals from my code by enclosing everything in a function, turning the globals into “pseudo globals,” that are all accessible from anywhere inside that function block.

(function(){

var g = 1;

var func f1 = function () { alert (g); }

var func f2= function () { f1(); }

})();

(technically this is only for my “release version”, where I append all my files together into a single file and surround them with the above….my dev version still has typically one global per js file)

This all works great except for one thing…there is one important place where I need to access some of these “globals” by string name. Previously, I could have done this:

 var name = "g";
 alert (window[name]);

and it did the same as

 alert(g);

Now — from inside the block — I would like to do the same, on my pseudo-globals. But I can’t, since they are no longer members of any parent object (“window”), even though are in scope.

Any way to access them by string?

Thanks…

  • 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-14T16:45:53+00:00Added an answer on May 14, 2026 at 4:45 pm

    Basically no, as answered indirectly by this question: Javascript equivalent of Python's locals()?

    Your only real option would be to use eval, which is usually not a good or even safe idea, as described in this question: Why is using the JavaScript eval function a bad idea?

    If the string name of those variables really and truly is defined in a safe way (e.g. not through user-input or anything), then I would recommend just using eval. Just be sure to think really long and hard about this and whether there is not perhaps a better way to do this.

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

Sidebar

Related Questions

I have an application right now that starts a process, then opens a file
I am trying to get the handle of a window from a process. Now,
I am revamping a website that (now) uses Prototype framework. In the process of
I am currently in the process of removing html tags from fields within an
I have a python process running now , but it hangs with no log、no
I went through the dev portal provisioning process twice now trying to get it
Right now, I'm extremely frustrated because I was in the process of developing some
i have created a process using the Process class. now i need to restrict
I just started to learn about mod rewrite process. Now, I got some problems
I'm using C# and Process newProcess = Process.Start(someProgram.exe); This someProgram.exe has a form that

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.