我有以下js片段:
<script language="javascript">
function test() {
this.a = 10;
};
test.prototype.next = function () {
alert('before: ' + this.a);
$.ajax({
url: 'some-url',
async: true,
type: 'POST',
dataType: 'json',
success: this.callback
});
};
test.prototype.callback = function () {
alert('after: ' + this.a);
};
$(document).ready(function () {
var test1 = new test();
test1.next();
});
</script>
它总是产生结果:之前:10 之后:未定义。
为什么在 $.post 的回调函数中,类的属性是未定义的。有人可以帮我吗?非常感谢。