I've found lots of creative ways to set default parameters in ES5 & ES6 but I have yet to see a simple example of how to override default parameters in JavaScript. Take this example:
new Connection(host, port = 25575, password, timeout = 5000)
The default timeout is fine but the port number is not. When calling this function, JavaScript always treats the second parameter as the password parameter:
myConnection = connFactory.getConnection(process.env.IP,
process.env.PORT,
process.env.PASSWORD)
This code results in an authentication error because the second parameter is assumed to be password. How can I override the default parameter for port without modifying the original function definition?
new Connection(host, port = 25575, password, timeout = 5000)what kind of syntax is this? Can you show us a more complete example of your code? We have no idea whatgetConnectionlooks like, so how can we help you with it?port. So I would guess the problem is somewhere else. Please create a minimal example that allows to reproduce the problem.getConnectionlook like? It sounds like there is something wrong intogetConnectionrather than default values