I have a javascript class to manage my API calls (here TimelinesManager), and I need to call a method of my manager (same class, named arrayToObject) inside the XMLHttpRequest.onload.
I tried to access it with this.arrayToObject() and TimelinesManager.arrayToObject() but I get an error meaning that it's not a function (TypeError: this.arrayToObject is not a function).
class TimelinesManager {
getTrends(access_token, start, limit, callback) {
// Create a request to API
var request = new XMLHttpRequest();
request.open('GET', 'https://api.extopy.com/timeline/trends.php', true);
request.onload = function () {
var data = JSON.parse(this.response);
if (request.status == 200) {
// Here I try to access to my class method
callback(this.arrayToObject(data));
}
};
request.send();
}
// The method I want to call
arrayToObject(data) {
// Here I proceed my data
}
}
How can I access to this class method?