When working with a callback function, I am having trouble accessing this
. Instead, it seems to be pointing to the AJAX object rather than the object that initially invoked the onClickEmail
function. I attempted to store a reference in a variable called that
, but this did not resolve the issue.
Is there something wrong with my approach here?
onClickEmail() {
var that = this;
var hey = "xyz"
$.ajax({
url: 'http://rest.learncode.academy/api/test123/tweets'
}).then(function(response) {
console.log(hey);
console.log(that);
});
}
My main question is why I can access the value of the hey
variable, but that
remains undefined.