我试图在构造函数中设置一个可以由嵌套函数表达式调用的变量.不太确定如何做到这一点
var test = function() {
var a;
function test(a, b, c) {
this.a = a;
this.b = b;
this.c = c;
}
test.getvariableA = function() {
//not returning a variable that is supposed to be set by the constructor
console.log(this.a);
};
return test;
}();
var t = new test("pizza", "pasta", "steak");
//does not return the variable
test.getvariableA();
//this returns the variable
console.log(t.a);Run Code Online (Sandbox Code Playgroud)
test.getvariableA();
这应该返回构造函数设置的变量.也许我对另一种语言感到困惑,谢谢你提前帮忙.