Currently, I am working on a JavaScript code snippet where I am attempting to set the 'obj' variable from the success and error callbacks. However, it seems like the scope of the 'toLinkInfo' function is not encompassing these callbacks? No matter what I try, I always end up receiving null as the output from this function. I have experimented with different approaches but none seem to resolve the issue. Perhaps my familiarity with C & its counterparts is clouding my judgment here. What steps can I take to overcome this challenge?
LinkInfoGrabber.prototype.toLinkInfo = function() {
var obj = null;
$.ajax({
url: this.getRequestUrl(),
success: function(raw) {
obj = new LinkInfo(raw);
},
error: function(jqXHR, textStatus, errorThrown) {
obj = new LinkInfoException(jqXHR, textStatus, errorThrown);
},
dataType: 'html'
});
if (obj instanceof LinkInfo) {
return obj;
} else {
throw obj;
}
}