I would like to be able to .then() a instantiated object while following the Promise standards.
Or is this not recommended?
I tried the following but I don't think it's the right approach...
class MyClass extends Promise {
constructor(){
this.loaded = false;
//Non promise third-party callback async function
someAsyncFunction( result => {
this.loaded = true;
this.resolve(result);
}
}
}
const myClass = new MyClass();
myClass.then( result => {
console.log(result);
console.log(myClass.loaded);
// >>true
})
Edit:
What I ended up doing was the following, but I'm not sure about using .load().then()
class MyClass {
constructor(){
this.loaded = false;
}
load(){
return new Promise( resolve => {
//Non promise third-party callback async function
someAsyncFunction( result => {
this.loaded = true;
resolve(result);
}
})
}
}
const myClass = new MyClass();
myClass.load().then( result => {
console.log(result);
console.log(myClass.loaded);
// >>true
})