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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:48:50+00:00 2026-05-27T04:48:50+00:00

I was reading Crockford’s tutorial http://javascript.crockford.com/private.html . private variables are implemented by function inside

  • 0

I was reading Crockford’s tutorial http://javascript.crockford.com/private.html.
private variables are implemented by function inside constructor that makes possible to associate private variables to closure.

Generally javascript libraries are open, so anyone can see and modify the private variables by modifying the inner function of constructor thru instances/objects. like this:
c1.radius = function (){return 500;};

Be more precisly: In real OOPS no one can modify private variable by objects but here we can.

Can anyone please suggest me the way to make it full tamper proof like JAVA or C?

function Circle(radius) {

this.radius = function(){ return radius;}

}

Circle.prototype = {
   constructor: Circle,
   area: function(){
       return (Math.PI)* (Math.pow(this.radius(),2));
   }
};

c1 = new Circle(5);
console.log(c1.radius());
console.log(c1.area());
c1.radius = function (){return 500;};
  • 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-27T04:48:51+00:00Added an answer on May 27, 2026 at 4:48 am

    1st off, don’t worry too much about making it tamper proof. If somebody really wants to, they’ll be able to access what they want.

    2ndly, you can’t really do this unless you’re using ECMAScript 5 (IE9+, Safari 5+, Chrome 7+, FF 4+). If you’re using an ES5 browser, you can do what you want using the Object.defineProperty method, or using Object.create:

    function Circle(radius) {
        Object.defineProperty(this, 'radius', {
            value: radius
        });
    }
    

    NOTE: When using Object.create or Object.defineProperty, properties are by default non-writable, non-configurable (type can’t be changed and property can’t be deleted), and non-enumerable (won’t show up in for(var x in obj) constructs).

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

Sidebar

Related Questions

I've been playing around with prototypal inheritance after reading http://javascript.crockford.com/prototypal.html and having a bit
I remember reading in Douglas Crockford's Javascript the Good Parts book that there is
Reading the documentation at http://jersey.java.net/nonav/documentation/latest/client-api.html#d4e704 makes me think that ClientFilter s are processed in
Just finished reading Crockford's JavaScript: The Good Parts and I have a question concerning
On Stackers' recommendation, I have been reading Crockford's excellent Javascript: The Good Parts .
I just started reading on Douglas Crockford's Javascript The Good parts where he explains
I was reading Douglas Crockford's web page, JavaScript: The World's Most Misunderstood Programming Language
I'm not a Javascript person normally, but I've been diving in, reading Douglas Crockford's
I'm just reading about Prototypes in JavaScript and Douglas Crockford offers and excellent way
I remember reading somewhere (I think it was in one of Crockford's papers) 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.