To call a function from another, we have to use this references. For e.g.
var oReq = new XMLHttpRequest();
oReq.onload = this.reqListener;
oReq.onerror = this.reqError;
oReq.open('get', './api/some.json', true);
oReq.send();
reqListener() {
console.log('reqListener called');
var data = JSON.parse(this.responseText);
console.log(data);
}
reqError(err) {
console.log('reqError called');
console.log('Fetch Error :-S', err);
}
If this is omitted from the onload assignment, then it complaints that the method not found.
References
No comments:
Post a Comment