I'm having a bit of a problem regarding global variables in that when I hit this block of code:
if(done === true){
console.log(songList);
}
the values of done and songList are now gone, however if I output them with console.log immediately after assign done=true then they carry the expected values (songList is built up in the function run by the eval statement). Can anyone explain why this is?
var song = {name:"", price:"", artist:"", image:""};
var done = false;
var songList = [];
function runJSON(network,searchType){
var URL = returnURL(network,searchType,$('#song_field').val().split(' ').join("+"));
$.getJSON(URL, function(data){
if(document.getElementById("box") !== "undefined"){
clearScreen();
createCols();
}
eval(network + "(data);");
done = true;
});
if(done === true){
console.log(songList);
}
}