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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:17:46+00:00 2026-05-14T07:17:46+00:00

I am a new programmer, and I started in C and am now starting

  • 0

I am a new programmer, and I started in C and am now starting to enjoy JavaScript and a tiny bit of PHP more. Lately I’ve heard the terms ‘private’ and ‘public’ functions a lot. Could anybody give an explanation of the both and how they are of use to a programmer?

And I’m probably totally wrong here… but is a

(function(){}) 

in javascript a private function?

  • 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-14T07:17:47+00:00Added an answer on May 14, 2026 at 7:17 am

    The terms “public” and “private” aren’t really appropriate with Javascript. The key is this: do you have a way to refer to some function you know to exist? That is, can you refer to it by name (either directly or as a property of another object you can reference)? If so, congratulations, you can call the function. If not, then you can’t.

    What this means is that the “publicness” of a function is not a static thing as it is in something like Java or C. Consider:

    var x = (function() {
      function maybePrivate() { return "my privates!"; }
    
      return {
        getMyPrivates: function() {
          var rv = maybePrivate;
          this.getMyPrivates = function() { return null; };
          return rv;
        }
      };
    })();
    

    Weird. So now “x” is an object, and you can see that there’s a “maybePrivate” function in there. However, that name — “maybePrivate” — doesn’t do you any good, because from outside x you can’t use the name to get to the function.

    However, that weird object has another function, called “getMyPrivates”, and you can get to it. When you call it, you get back a reference to the “maybePrivate” function, which you can then use to call that function. Now, is “maybePrivate” still private? Well, if you do this:

    alert(x.getMyPrivates()());
    

    you’ll see the “my privates!” message. So it looks like “maybePrivate” isn’t so private anymore. However, if you try that again, it won’t work, because “getMyPrivates” arranges for itself to be dummied out after it is called the first time.

    The point of that little trip through the looking glass is to illustrate that Javascript is dynamic. The only thing that’s really “static” is that once you’ve sealed up a function inside a closure (like “maybePrivate” in the above example), you can’t force it to be revealed from outside the object (at least, not without going through some really twisty contortions; the language is so mushy that it’s dangerous to claim that something is “impossible” :-). That object in the example could choose to reveal its “private” stuff, but it can also choose not to.

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

Sidebar

Related Questions

I'm a hobbyist (and fairly new) programmer who has written several useful (to me)
I'm a new Windows programmer and I'm not sure where I should store user
We have 2 new GIS programmer/analyst in our department (new to programming and ArcObjects)
I'm a relatively new Java programmer coming from C++/STL, and am looking for a
I am a MFC programmer who is new to C# and am looking for
Many years ago I remember a fellow programmer counselling this: new Some::Class; # bad!
I just re-read The Pragmatic Programmer (my third time reading it...I get something new
I am a programmer who writes a lot of code for desktop applications, now
I am just started working as a programmer last month, so there will be
I'm a new programmer, so please excuse any dumbness of this question, how the

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.