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
Post a Comment