Do functions attached to the prototype property not have closure
<p>I am trying to figure out how I can add methods to a constructor after I have created it.<br>
In my code below, I cannot use Person's prototype property to add a new public method which has access to Person's vars. (Do the functions attached to the prototype property not close over the vars in the main function).<br>
Unlike the first way, the second way works - Person 2. seems like these are called privileged methods -<a href="http://www.crockford.com/javascript/private.html" rel="nofollow">http://www.crockford.com/javascript/private.html</a>.</p>

<pre><code>function Person(name, age){}
Person.prototype.details = function(){ 
    return "name: "+name+", age: "+age;
};

function Person2(name, age){
 this.details = function(){ 
    return "name: "+name+", age: "+age;};
}

var per1 = new Person("jim", 22);
var per2 = new Person2("jack", 28);

per1.details();
//=&gt; ReferenceError: age is not defined
per2.details();
//=&gt; "name: jack, age: 28"
</code></pre>
