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;};