I thought that functions created using .prototype were supposed to be able to access local variables. Here is what I'm talking about:
function obj() {
var a = "String";
this.innerPrint = function() {
document.write("<p>" + a + "</p>");
};
}
obj.prototype.outerPrint = function() {
document.write("<p>" + a + "</p>");
};
var inst = new obj();
inst.innerPrint();
inst.outerPrint();
What I thought would happen is that both of these functions would do the same thing. But what actually happened is outerPrint doesn't have access to the variable a. Could someone explain to me how you get locals in a prototype function.
Here is a fiddle running this code: http://jsfiddle.net/Wryte/mxXzg/
By the way, I want to use prototype functions because then each instantiation of the object doesn't have a copy of the function but they each point to the same one.