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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:14:48+00:00 2026-05-31T18:14:48+00:00

for the longest time now i’ve used object literals to replace multiple var statements

  • 0

for the longest time now i’ve used object literals to replace multiple var statements within my code. here’s a typical example:

(function(){
  var replaceVars = {};
  function x(){
    replaceVars.num=886;
}
  function y(){
    x();
    replaceVars.cal = replaceVars.num*99;
    return replaceVars.cal;
  }
})();

so my question is: is there anything wrong with this? i mean the up sides i can see are that: 1) there is only one var statement within the whole of my code. 2) within the closure all children can access it(which means replaceVars properties become global within the scope of the closure. it’s like making a global-like child object (the closure) within the true global object(the window) 3) i can pre-define properties that are ready to go immediately:

var replaceVars={
something1:”some value”,
something2:”some other value”
}

so can anyone think of any downsides to my way of doing things?

  • 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-31T18:14:50+00:00Added an answer on May 31, 2026 at 6:14 pm

    I don’t think there’s anything wrong with using a container object. Though, I’d make a habit with it of declaring the variables needed for the related code:

    var replaceVars = {
        num: null,
        cal: null
    };
    

    But, then again, this works as well:

    (function () {
      var num, cal;
    
      function x(){
        num = 886;
      }
    
      function y(){
        x();
        cal = num * 99;
        return cal;
      }
    })();  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For the longest time I've used jQuery to hack together web sites. Now I'm
For the longest time now I've been trying to convert HTML pages containing large
I've been beating my head against this reg ex for the longest time now
I'm wondering for some time now why this fails: if (longest.length >= 3) {
For the longest time I've been interested in building a cluster of heterogeneous nodes
What algorithm can be used to find the longest path in an unweighted directed
This one has bugged me for the longest time and a great question to
I've been wondering for the longest time WHY I actually need a live resource
For the longest time, I've been using the following basic formatting for SQL queries
For the longest time, I've been using MySQL servers to handle data (in JAVA,

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.