I have this class which we're going to call Connection
, and there's a function in this class named Disconnect
which returns a class named PartialConnection
. There are some arguments for both classes, but that shouldn't be taken into effect because it's quite complicated for such an example.
This is the class structure I'm working with as a sketch:
const BaseConnection = require("./BaseConnection.js");
const PartialConnection = require("./PartialConnection.js");
class Connection extends BaseConnection { // BaseConnection is also a class with standard variables every type of connection should have. PartialConnection also extends from this.
constructor () {
...
}
Disconnect() {
return new PartialConnection();
}
}
Before you all ask, the path to ./PartialConnection.js
is correct and it's set with module.exports = PartialConnection;
with PartialConnection
being the class name.
File PartialConnection.js
const Connection = require("./Connection");
const BaseCon = require("./BaseConnection");
class PartialConnection extends BaseCon {
constructor () {
...
}
}
module.exports = PartialConnection;
Although, I must say that the colouring of the module.exports = PartialConnection
is off like shown here: https://i.stack.imgur.com/I9hpG.jpg - I also should say that, when executing the same function but for the PartialConnection to Connection, it just works fine. It has something to do with circular references.
When I create a new instance of Connection
and run the Disconnect
function, it returns the following error:
/Users/---/Desktop/Projects/QDB/lib/Connections/Connection.js:87
return new PartialConnection();
^
TypeError: PartialConnection is not a constructor
at Connection.Disconnect (/Users/---/Desktop/Projects/QDB/lib/Connections/Connection.js:87:16)
at process.<anonymous> (/Users/---/Desktop/Projects/QDB/lib/Connections/Connection.js:76:75)
at process.emit (events.js:219:5)
(I blanked out my name for privacy.)
As you can see, it seems like I can't initiate and return a new class of some sort. This used to work about a few weeks ago, but now it doesn't.
Version;
$ node -v
v13.3.0
$ npm -v
6.14.2
And for clarification - I'd like it to almost-literally terminate the current class and return a new class that doesn't allow you to make adjustments to the Connection
class.
If you have any solutions or if you can help in any way, it's much appreciated!