我有对象
var MyObject = (function (){
var MyObject = function (a,b){
this.A = a;
this.B = b;
this.C;
}
MyObject.prototype.PublicFunction = function(){
var someVariable = 123; //this.A and this.B are both fine here.
var self = this;
$.ajax({
type: "POST",
url: "Default.aspx/PageMethod",
data: "{" + args + "}",
dataType: "json",
async: true,
cache: false,
contentType: "application/json; charset=utf-8",
success: function (data, status) {
//this.A = undefined, this.B = undefined, this.C = the data.
self.C = data.d
},
error: function(xhr, status, error){
alert('tears');
}
});
}
return MyObject;
}());
当我进入原型函数this.A\B
时,都是来自构造函数的值。ajax 调用执行后this.A\B
都是undefined
. 我不确定在这里做什么。我可能不了解我需要的对象的范围。任何人都可以帮忙吗?