inheritance - how does javascript private variable work in prototype implementation -


http://msdn.microsoft.com/en-us/magazine/ff696765.aspx

this website shows example

function circle(radius) {   this.getradius = function() {     return radius;   };   this.setradius = function(value) {     if (value < 0) {       throw new error('radius should of positive value');     }     radius = value;   }; } 

vs

circle.prototype.getradius = function() {   return this._radius; }; circle.prototype.setradius = function(value) {   if (value < 0) {     throw new error('radius should of positive value');   }   this._radius = value; }; 

and on page states

"however, in such case, lose luxury of having private members, , have resort other means such denoting privacy through convention (underscored property names). comes down making choice between having private members or having more efficient implementation."

how using prototype this._ losing luxury of "truly private" members?, prototype.this not considered reference self?

if property on object visible code in function on prototype object, it's visible code anywhere.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -