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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:09:30+00:00 2026-05-13T23:09:30+00:00

I’m working on a large project that is organized like so: Multiple javascript files

  • 0

I’m working on a large project that is organized like so:
Multiple javascript files are included as needed and most code is wrapped in anonymous functions…

// wutang.js

//Included Files Go Here

// Public stuff
var MethodMan;

// Private stuff
(function() {

var someVar1;

MethodMan = function(){...};

var APrivateMethod = function(){...};

$(function(){
//jquery page load stuff here
    $('#meh').click(APrivateMethod);
});
})();

I’m wondering about a few things here. Assuming that there are a number of these files included on a page, what has access to what and what is the best way to pass data between the files?

For example, I assume that MethodMan() can be accessed by anything on any included page. It is public, yes?

var someVar1 is only accessible to the methods inside that particular anonymous function and nowhere else, yes? Also true of var APrivateMethod(), yes?

What if I want APrivateMethod() to make something available to some other method in a different anonymous wrapped method in a different included page. What’s the best way to pass data between these private, anonymous functions on different included pages? Do I simply have to make whatever I want to use between them public? How about if I want to minimize global variables?

What about the following:

var PootyTang = function(){
    someVar1 = $('#someid').text();
    //some stuff
};

and in another included file used by that same page I have:

var TangyPoot = function(){
    someVar1 = $('#someid').text();
    //some completely different stuff
};

What’s the best way to share the value of someVar1 across these anonymous (they are wrapped as the first example) functions?

  • 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-13T23:09:31+00:00Added an answer on May 13, 2026 at 11:09 pm

    You’re right – any variable declared inside the anonymous function stays inside the anonymous function. So from the first example, MethodMan will be available to everything, and someVar1 is indeed private.

    When you talk about ‘including’ files, imagine you just copy and paste the code from all the separate files into one big file. This is essentially what happens. If you want someVar1 to be available to different “modules” (since that’s what you’re emulating w/ the anonymous functions), then declare it outside any of the modules, e.g.:

    var someVar1 = "initialValue";
    (function() { //module 1
        var PootyTang = function(){
            someVar1 = $('#someid').text();
            //some stuff
        };
    })();
    (function() { //module 1
        var TangyPoot = function(){
            someVar1 = $('#someid').text();
            //some stuff
        };
    })();
    

    In this case, since someVar1 is global, they will access the same variable. But note that if you did this instead:

    (function() { //module 1
        var TangyPoot = function(){
            var someVar1 = $('#someid').text();
            //some stuff
        };
    })();
    

    You’d be creating a separate local variable called someVar1 that wouldn’t affect the global.

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

Sidebar

Ask A Question

Stats

  • Questions 353k
  • Answers 353k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For this purpose I generally use an expression binding class… May 14, 2026 at 7:39 am
  • Editorial Team
    Editorial Team added an answer This task is simple if you choose appropriate format for… May 14, 2026 at 7:39 am
  • Editorial Team
    Editorial Team added an answer There are several different pieces of information relating to processors… May 14, 2026 at 7:39 am

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.