我正在尝试从 Javascript 中的函数外部访问内部函数,但它只打印“未定义”而不是打印函数的源代码。如何changeBlah
从范围之外修改函数的原型exampleFunction
?
var blah = "";
function exampleFunction(theParameter){
this.blah = theParameter;
this.changeBlah = function(){
this.blah += "gah";
}
}
var stuff2 = new exampleFunction("Heh!");
alert(stuff2.blah);
stuff2.changeBlah();
alert(stuff2.blah);
alert(exampleFunction.changeBlah); //now why doesn't this work? It doesn't print the function's source code, but instead prints undefined.