我如何访问在函数中定义的变量,如下所示:
var functionVar = function(){
this.var = 1;
}
console.log(functionVar().var); //MH - obviously this doesn't work, but I'm looking for the command that will log that variable
最佳答案
您可以像这样访问
var functionVar = function(){
this.var = 1;
}
var o = new functionVar();
alert(o.var)