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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:04:43+00:00 2026-05-29T04:04:43+00:00

I have implemented an object as a closure in JavaScript, some of the methods

  • 0

I have implemented an object as a closure in JavaScript, some of the methods are public, some other are private:

var MyObject = (function(){

    function _hiddenMethod() {
        /* Do something fancy here, such as reading data 
        from an external source and storing it in 
        _hiddenVariable2 */
    } 

    var _hiddenVariable1 = 3;
    var _hiddenVariable2 = undefined;

    return {
        publicMethod: function() {
            _hiddenMethod();
            return _hiddenVariable1;
        };
    };

})();

Is there a way in which a (skilled) user could possibly read the content of _hiddenVariable2? I assume it knows its existence by having read the JavaScript code.

  • 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-29T04:04:44+00:00Added an answer on May 29, 2026 at 4:04 am

    There is no way I know of but it might depend on the javascript engine.

    Also keep in mind, that anyone can debug javascript and note whenever _hiddenVariable2 is set in the closure (write something like _hiddenVariable2 = 5 inside the _hiddenMethod, try developer tools for chrome and insert a breakpoint into the _hiddenMethod, and you will be able to see when _hiddenVariable2 is set).

    So a skilled user can know the current value of it if hes debugging the code in V8 for example.

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

Sidebar

Related Questions

I have implemented each function like this in JS: Object.prototype.each = function(fn){ for (var
Possible Duplicate: Can Read-Only Properties be Implemented in Pure JavaScript? I have an Object
I have implemented a set datatype in javascript based in a generic object type,
I have implemented DAO as follows, //pseudoCode public MyDAO{ private Session session; MYDAO{ this.setSession(HibernateUtil.getSessionFactory().getCurrentSession());
We have a COM object implemented with C++/ATL that includes a method which will
I have an own Tree object implemented in PHP. Say we have a tree
I have implemented drag and drop in my application, but am having some difficulty
I have implemented a class that extends System.Timers.Timer object. When I then save the
I have implemented the sort function in my codebehind, it works fine with words
I have implemented a custom IPrincipal that I set in protected void Application_PostAuthenticateRequest(Object sender,

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.