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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:17:41+00:00 2026-06-18T18:17:41+00:00

Ok, I don’t know if I am going to be able to fully describe

  • 0

Ok, I don’t know if I am going to be able to fully describe the scope of what I am doing, but hopefully I can convey some level of it here and hopefully someone will understand. So..

I have these global variables I am defining in my javascript ie:

var abc = '';
var def = '';
var ghi = '';

With these variables I am able to define them later in my script through functions. So they are then reusable by other functions later. That part I have down fine. Now I have an interesting notion that has me stumped where the. The variable is this case is ultimately an object I pass around from function to function, that I can use for various comparisons, and update it as needed. Now Ive reached a point where I need to redefine the whole object at the end of a particular function. But I am merely passing around the object itself so the reference is lost as to which object was the starting point.

So now I am trying to figure out is there a way I can redefine it, say my function is

function monkey(var)
{
   //code to do stuff
   //something here after stuff to redefine var as the object it once was referenced
   //example ghi = something_from_code_generation_above
}
monkey(abc);
monkey(def);
monkey(ghi);

where after making calls like that the abc object update, or the def object updates, or the ghi object updates. But keeping it confined within the function and not through a closure like

ghi = monkey(ghi);
  • 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-18T18:17:42+00:00Added an answer on June 18, 2026 at 6:17 pm

    The only way I know how to do this is by passing the enclosing scope as an extra parameter, and passing the name, rather than the value of the variable.

    monkey(window, "abc"); // sends the global variable "abc" and allows it to be modified
    
    function monkey(scope, name)
    {
        var v = scope[name];
        // do stuff to v
        scope[name] = whatever; // destructively updates the variable in the original scope
    }
    

    If you already know that all variables passed will be in a particular scope (e.g. they are all part of some known named object) You can just pass the variable name by string.

    If they are all global variables, as you indicate in your question, do:

    monkey("abc"); // instead of monkey(abc);
    function monkey(name)
    {
        var v = window[name];
        window[name] = whatever; // updates the global variable by name
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know what's going on, but for some reason my background image is not
Don't know whats exactly going on, but it's definitely killing my time for nothing.
Don't know if this is possible, but I have some code like this: val
Don't know if I'm over-thinking this or not.. but I'm trying to be able
Don't know why but I can't find a solution to this. I have 3
don't know if the title describes anything about what I'm trying to say but
don't know what happened in my jcrop selection. I think I pressed some keys
Don't really know how to formulate the title, but it should be pretty obvious
Don't know how to google for such, but is there a way to query
Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face

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.