我有一个类(你好),这个类有 foo 属性,这个属性必须在 xhr 请求后填充。如何设置foo
和XMLHttpRequest
如何调用afterLoad()
?
function Hello(){
this.foo = null;
this.process = function(){
var req = new XMLHttpRequest();
req.open('GET', 'http://some.url', true);
req.onload = function(){
// How to set Hello.foo in this context?
// And how to call Hello.afterLoad() from this context?
// this == XMLHttpRequest instance
};
req.send(null);
}
this.afterLoad = function(){
console.log(this.foo);
// Some stuff goes here
}
}