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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:23:07+00:00 2026-06-01T12:23:07+00:00

I put all my code in NS, similar to how jQuery is structured. I

  • 0

I put all my code in NS, similar to how jQuery is structured. I have a few variables global to NS, that I would like to enclose and then make accessible like this -> Global.variable_name.

Below is the way I did it. Is this good practice? Is there a better way to do this where I do not have to call var Global = new GlobalMaker()

I use all capitals for global CONSTANTS.

var NS = ( function ( window, undefined ) { /* all my code is here */ } )( )

/** (including this code)
 *GlobalMaker
 */

var GlobalMaker = function()
{
    this.tag_array = [];
    this.current_tag;
    this.validate_input_on;
    this.JSON_ON = 1;                              // selector between JSON and LON
    this.GATEWAY = 'class.ControlEntry.php';       // for Ajax calls
    this.PICTURES = '../pictures/';                // for composing tweets
    this.PASS = 0;
    this.FAIL = 1;
    this.NOTDEFINED = 2;
};
var Global = new GlobalMaker();

/**
 *Global 
 */

var Global = 
{
    tag_array:          [],
    current_tag:        0,
    validate_input_on:  0,
    JSON_ON:            1,                             
    GATEWAY:            'class.ControlEntry.php',       
    PICTURES:           '../pictures/',                
    PASS:               0,
    FAIL:               1,
    NOTDEFINED:         2
}
  • 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-01T12:23:08+00:00Added an answer on June 1, 2026 at 12:23 pm

    This does the equivalent, without using a constructor function:

    var Global = {
        tag_array: [],
        // current_tag, // huh?
        // validate_input_on, // huh?
        JSON_ON: 1,
        GATEWAY: 'class.ControlEntry.php',
        PICTURES: '../pictures/',
        PASS: 0,
        FAIL: 1,
        NOTDEFINED: 2
    };
    

    But I don’t understand the second two declarations that have no initialization.

    Note, though, that if you do this as you indicate above, this Global object is available only within that outer Arc function expression. It’s not truly global. Also note that the use of ‘global‘ (lowercase) is pretty common; you might want to consider a different varialbe name (perhaps ‘constants‘?)

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

Sidebar

Related Questions

I have a lot of code and would like to avoid posting it all
I have this piece of code that I would like to shorten... PackageManager p
I would like to know how to put all of my ListView rows into
I have a jquery fullcalendar . I would like to trigger jquery QTip (or
Good Morning All, I have code similar to the following try{ using(var tx =
I have jquery code that is being reused by a repeatable partial view on
First of all, do not be overwhelmed by the long code, I just put
We put all of our unit tests in their own projects. We find that
I've frequently encountered sites that put all of their JavaScript inside a namespace structure
In my project I have put all my css classes in the style sheets.

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.