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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:13:59+00:00 2026-06-07T05:13:59+00:00

When I put a comment above my variable or function with @private in it

  • 0

When I put a comment above my variable or function with @private in it what is it actually doing? I have looked at the documentation but I’m still not sure.

goog.provide('myproject');

/** @private */
myproject.foo = "bar";

I can still access it when I open up chrome’s development tools (myproject.foo). And…

goog.require('myproject');

window.addEventListener('load', function() {
    //this works.
    document.body.textContent = myproject.foo;
});

The above code still set’s the bodies textContent to equal “bar”, even when compiled. So what does @private actually do?

  • 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-07T05:14:02+00:00Added an answer on June 7, 2026 at 5:14 am

    The access control annotations @private, @protected, and @public are
    directives for the Closure Compiler that help developers enforce the
    desired level of visibility for properties and functions.

    To emit warnings for access violations use the Compiler flag:

    • –jscomp_warning=visibility

    To emit errors for access violations use the Compiler flag:

    • –jscomp_error=visibility

    Access control annotations are enforced on a per file basis,
    meaning that any properties annotated @private or @protected may be
    accessed anywhere within the same file. Also note that the compiler removes
    these annotations from the compiled code since they are not part of the
    JavaScript language.

    Example

    file1.js

    goog.provide('ns1');
    
    /**
     * Global private variable.
     * @private
     */
    ns1.global = 'foo';
    alert('ns1.global = ' + ns1.global); // OK in same file.
    
    
    /** @constructor */
    ns1.Constructor = function() {
      /** @private */
      this.secret_ = ns1.global;
    };
    
    ns1.instance = new ns1.Constructor();
    alert(ns1.instance.secret_); // No warning in same file.
    

    file2.js

    goog.provide('ns2');
    
    goog.require('ns1');
    
    alert('ns1.global = ' + ns1.global); // Not allowed.
    
    ns2.instance2 = new ns1.Constructor();
    alert(ns2.instance2.secret_); // Not allowed.
    

    With the flag --jscomp_error=visibility set, Closure Compiler emits the
    following errors.

    ERROR - Access to private property global of ns1 not allowed here.
    alert('ns1.global = ' + ns1.global);
                            ^
    ERROR - Access to private property secret_ of ns1.Constructor not allowed here.
    alert(ns2.instance2.secret_);
          ^
    

    See Visibility (private and protected fields) in the Google JavaScript
    Style Guide
    .

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

Sidebar

Related Questions

I am having trouble using the //TODO flag. When I put the //TODO comment
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I
I have a partial class in a dbml file. public partial class Comment string
I have a main function that does a lot of IO. At one point,
I've been able to find similar, but not identical questions to this one. How
Facebook offers a simple method to add a Facebook comment function on your personal
hi im not sure where to start on this as events and their handlers
I have a site [hosted on DreamHost], using WordPress for the main content, but
I have a text area which i put a 250 character limit on for
I am not sure what the most appropriate way to handle JPA objects that

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.