Details
-
Improvement
-
Status: Open
-
Critical
-
Resolution: Unresolved
-
3.7.0
-
None
-
None
Description
Java provides the ability to override a class constructor, which has allowed a Client or Connection class in Java to be instantiated using varying different parameters. Javascript classes only allow a single constructor. This limits a developer's ability to access or modify class properties for a Client or Connection object.
Example:
A DriverRemoteConnection object in gremlin-javascript can only be instantiated via:
let drc = new DriverRemoteConnection(some_url);
A developer would not be able to create a Client object first and create a new DriverRemoteConnection object based on the Client as they would be able to do using the Java GLV.
Similarly, if a user needed to gain access to an underlying Client or Connection object from within a DriverRemoteConnection, they would be accessing these properties using the _client or _connection variable names. The underscore prefix typically denotes that these should be viewed as private class properties. As such, we should be treating these as private until a time comes as to when we can adopt actual private class properties and functions (a fairly new concept added to JS in ES2019).
To address these issues, I suggest we add setter and getter functions to the respective classes that would allow a user to more properly interact with class properties that cannot be defined via overridden constructor.