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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:11:28+00:00 2026-06-02T19:11:28+00:00

I have seen the following code var MODULE = (function () { var my

  • 0

I have seen the following code

var MODULE = (function () {
var my = {},
    privateVariable = 1;

function privateMethod() {
    // ...
}

my.moduleProperty = 1;
my.moduleMethod = function () {
    // ...
};

return my;
 }());

the properties can be accessed like MODULE.moduleProperty …right?
But how to access globals privateVariable and privateMethod() inside the module(which are globals insode the module …right?)

  • 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-02T19:11:29+00:00Added an answer on June 2, 2026 at 7:11 pm

    You can only access them from WITHIN the module code itself as such:

    var MODULE = (function () { 
     var my = {},
     privateVariable = 1;
     function privateMethod() {
      alert('this is private!');
     }
    
     my.moduleProperty = 1;
     my.moduleMethod = function () {
      privateMethod();
      return privateVariable;
     };
     return my;
    }());
    

    Doing this:

    MODULE.moduleMethod();
    

    Will call private method (and alert ‘this is private!’) and return the value of privateVariable.

    There is no way to access privateVariable or privateMethod outside the MODULE scope.

    var MODULE = (function() {
     //...declare your module as above
    }());
    
    console.log(MODULE.privateVariable); //logs undefined
    

    Hopefully that helps clear it up for you.

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

Sidebar

Related Questions

I have seen the following code in a website... what does this mean?.Can i
I have seen a web page source code containing the following css declaration at
Can someone recommend a hosted solution that answers the following requirements (I have seen
I am using jquery 1.3.2 and have the following code, $(document).ready(function () { $.ajax({
I have the following code in a test case on jsPerf: var arr =
Im currently in process of learning Javascript. And I have seen the following code,
I have the following code called on WM_MOVE procedure TForm15.WMMove(var Message: TMessage); begin if(
guys i have seen following code in internet select round(abs(months_between(sysdate,add_months(hire_date,12*(round((months_between(sysdate,hire_date)/12))))))) from employees unfortunately there
I have seen the following code: [DefaultValue(100)] [Description(Some descriptive field here)] public int MyProperty{...}
In a few examples of code I have seen the following when calling a

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.