What is difference between using this keyword vs variable name in XMLHttpRequest callback?
var req = new XMLHttpRequest();
req.open("GET", encodeURI(uri), true);
req.onreadystatechange = function () {
if (this.readyState == 4) {
req.onreadystatechange = null; //avoid memory leaks
if (this.status == 200) {
var res = JSON.parse(req.responseText).d;
console.log(res);
}
}
};
req.send();
Can I just use req instead of this, like if (req.readyState == 4)
?