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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:52:26+00:00 2026-06-12T00:52:26+00:00

So there has been much discussion on the topic of accessing private members inside

  • 0

So there has been much discussion on the topic of accessing private members inside of prototype methods. The thought occurred to me that the following should work:

function Test(){
    var private = "Private";
    this.instance = function(){
        return private;
    };

    Test.prototype.getPrivate = function(){
        return private;
    };
}
var test1 = new Test();
var test2 = new Test();
console.log(test1.instance === test2.instance);  // false
console.log(test1.getPrivate === test2.getPrivate);  // true

Turns out it does, in fact, work. I’m concerned, however, that there might be a drawback to doing this.

So my question is: Is there a drawback?

  • 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-12T00:52:27+00:00Added an answer on June 12, 2026 at 12:52 am

    This doesn’t work the way you probably expect, as test1‘s getPrivate() gets test2‘s private.

    function Test(value){  
        var private = value;  
        this.instance = function(){ return private; };
    
        Test.prototype.getPrivate = function(){  
            return private;  
        };  
    }  
    var test1 = new Test("test1");  
    var test2 = new Test("test2");
    console.log(test1.getPrivate()); // test2
    console.log(test2.getPrivate()); // test2
    

    so it really doesn’t matter if it is inefficient as it doesn’t work.

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

Sidebar

Related Questions

There has been much discussion about how to choose the #blocks & blockSize, but
In the Zend Framework Quickstart , there has been a change from models that
Has there been discussion around how to resolve equivalent openids? Meaning, I personally have
There was this problem that has been asked about implementing a load byte into
There has been a considerable amout of discussion about code metrics (e.g.: What is
I know there has been much shout about the goodness of MVC pattern. My
There has been some discussion on the SO community wiki about whether database objects
I've recently come on board with a PHP application. There has not been much
There has been some discussion in abandoning our CI system (Hudson FWIW) due to
Ok, I'm developing an application that has been in pretty much continous development over

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.