i have a sample es6 class that perform api calls and callback to the class
when i to call the class using this
keyword it fails with undefined
how can i make the heritance to work?
class class1 {
function1_1() {
var ap = new api('endpoint',this.function1_2,{"x":"Y"});
ap.call()
}
function1_2(){
// do some code
this.function1_1 // fail with error - undefined
}
}
class api {
constructor(endpoint,cb,opts) {
this._endpoint = endpoint;
this._cb = cb;
this._opts = opts;
}
call() {
var cbm = this.cb;
fetch('/apis/'+this.endpoint,{method:"post",body: JSON.stringify(this.opts)}).then(function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' + response.status);
return;
}
response.json().then(cbm);
}).catch(function(err) {
console.log('Fetch Error :-S', err);
});
}
}