Skip to content Skip to sidebar Skip to footer

Typescript Javascript Class, Two Instances This Get Mixed When Returning Promise

I have a typescript app that it is mixing 'this' context inside a class. This class is responsible to setup new Express server instance. If I track 'this' with debugger and node --

Solution 1:

The issue is probably inside the EchoServer class, namely here:

this.options = Object.assign(this.defaultOptions, config);

Thats equal to:

this.options = this.defaultOptions;
 Object.assign(this.defaultOptions, config);

I assume you actually wanted to do:

this.options = Object.assign({}, this.defaultOptions, config);

which creates an own options object for each instance.

Post a Comment for "Typescript Javascript Class, Two Instances This Get Mixed When Returning Promise"