Uncaught TypeError: Cannot set property 'getV' of undefined
Uncaught TypeError: Cannot set property 'getV' of undefined
我在javascript中有这个功能:
function test(obj,arg1,arg2) {
...
...
this.getV=function() {
var x=2;
return x;
}
}
我该如何解决这个问题?
function test(obj,arg1,arg2) {
...
...
this.getV = function() { // getV() is wrong you are declaring function
var x = 2;
return x;
}
}
var testObj = new test();
testObj.getV(); // return 2
这一行:
this.getV()=function(){ var x=2; return x; }
导致错误。 getV() 未定义!你必须这样定义它:
this.getV = function(){ var x=2; return x; }
我在javascript中有这个功能:
function test(obj,arg1,arg2) {
...
...
this.getV=function() {
var x=2;
return x;
}
}
我该如何解决这个问题?
function test(obj,arg1,arg2) {
...
...
this.getV = function() { // getV() is wrong you are declaring function
var x = 2;
return x;
}
}
var testObj = new test();
testObj.getV(); // return 2
这一行:
this.getV()=function(){ var x=2; return x; }
导致错误。 getV() 未定义!你必须这样定义它:
this.getV = function(){ var x=2; return x; }