Accessing a local variable using prototype
<p>I have a Class that has a private variable with a public setter/getter function:</p>

<pre><code>function Circle(rad) {
    var r = rad;

    this.radius = function(rad) {
        if(!arguments.length) return r;
        r = rad;
        return this;
    }
}

var shape = new Circle(10);
console.log( shape.radius() ); // 10
shape.r = 50;
console.log( shape.radius() ); // 10
</code></pre>

<p>How can I replicate this using <code>Object.prototype</code>? Or, when would I want to use a closure instead of <code>Object.prototype</code>? This is the closest I could come up with, but as you can see, you can change the property directly.</p>

<pre><code>function Circle(r) {
    this.r = r;
}

Circle.prototype.radius = function(r) {
    if(!arguments.length) return this.r;
    this.r = r;
    return this;
};

var shape = new Circle(10);
console.log( shape.radius() ); // 10
shape.r = 50;
console.log( shape.radius() ); // 50
</code></pre>
