I've been reading through different types of posts here regarding my topic but I couldn't fully understand the concept of closures and their scopes. I have the following code:
var result = loadFile('input/file.txt');
function loadFile(file) {
var test;
$.get(file)
.done(function(data) {
test = data.split("\r\n");
})
.fail(function(){
alert("failed loading file");
});
return test;
}
I simply want to assign the closure value, that is the split, to the local variable one level above the .get function. Is this possible? In the example above the local test variable never gets populated.
Thank you for helping me!