Could you please help to understand what can be wrong while using promises in callback on parent class and then trying to set properties on child class?
I'm using nodejs v8.2.1
Here is example of base class:
class CGLBase extends CAuthClient
{
constructor(req, res)
{
return new Promise(resolve => {
super(req, res, (authClient) => {
this.setAuthClient(authClient);
resolve(this);
});
});
}
setAuthClient(authClient)
{
//setting authClient (this.auth will contain property)
}
}
And here example of child class:
class СSheet extends CGLBase
{
constructor(document, urlRequest, urlResponse)
{
super(urlRequest, urlResponse);
this.document = document;
this.someAnotherProp = "some property";
//etc..
}
someFunc()
{
//using this.document and this.auth
}
}
After that I'm creating instance of СSheet and trying to set properties:
var document = { ... }; //here I create object
(async () => {
var docSheet = await new СSheet (document, req, res);
docSheet.someFunc();
console.log(docSheet.auth); //return correct property
console.log(docSheet.document); //return undefined. why...
})();
So, I don't understand why property this.document wasn't set. I see only this.auth that was set in the async callback. All properties except this.auth are undefined.
I will be very grateful for advice or help.
Thank you in advance.