HttpService.test(account, pwd, this.test);
private test(params : any)
{
this.node.destroy(); //报错,找不到this
}
static HttpService.test(callback ?: ((params : any) => void))
{
let url = “http…”;
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 207) {
let response = xhr.responseText;
let data = JSON.parse(response);
callback(data);
} else {
callback(null);
}
} else {
console.log(“onCreateAccountStateChange xhr.readyState is:”, xhr.readyState, "xhr.status is: ", xhr.status)
}
};
xhr.open(“POST”, url, true);
xhr.send();
}
当然先试用静态变量保存this是可以的,但是有办法可以直接调用this吗?我使用的TS