I'm wondering why the variable "gists" is not being modified in the function bellow on the arrow. It's declared outside the function so it should be global. I tried putting the variable as parameters to the functions but that doesnt work either. But when I access the variable outside the function it doesn't show that it has been modified. Is there a reason for this?
var gists; // = [];
function getGists() {
var request = new XMLHttpRequest();
if (!request) {
throw 'Unable to create HttpRequest.';
}
var url = 'https://api.github.com/gists/public';
//var url = 'https://api.github.com/gists/users/:smithjoe123/gists';
request.onreadystatechange = function () {
if (this.readyState == 4) {
//console.log(this.responseText);
var txt = this.responseText.trim("\"");
gists = JSON.parse(txt);
gists = 5544; //<<<<<<----------VARIABLE HERE NOT MODIFIED
console.log("xxyyiii<<<<<<<<!!");
}
};
request.open('GET', url);
request.send();
}
getGists();
console.log(gists); //here it does not show that it has been modified
//console.log(gists[0].user);