I am creating a model-like Class that, when initialized, fires off an AJAX request. I want to store the response of that request as a property of the new object, so that I can use the data it returns. Problem is, the value of 'this' within the promise (.done) is the XHR object, not the object.
How am I thinking about this wrong?
function TweetData() {
this.tweetList = [];
var data = $.getJSON('data/tweets.json');
data.done(function(data){
for (var i = 0; i < data.length; i++) {
var obj = data[i];
this.tweetList.push(obj.text);
}
});
} //end constructor