I had a similar situation to this and was curious why p
does not know what b
is, since p
is defined within the same function as b
.
var a = "a";
window.onload = function() {
var b = "b";
var p = new Person();
p.doIknowAorB();
}
function Person() {
this.name = "nate";
}
Person.prototype = function(){
var doIknowAorB = function() {
console.log(a);
console.log(b);
};
return {
"doIknowAorB": doIknowAorB
}
}();