There are mainly two problems of putting multiple construction logic inside the constructor. First, it will become difficult to manage when there are many cases to take care of. It is because the parameter instantiations are not clear. Like in the example above, the paymentObject is dependent on the paymentType, which we won’t know about without looking into the rest of the code.

Another issue is flexibility. When you want to have a different number of parameters based on different contexts, it will become troublesome. You need to pad null in the arguments sometimes when you want to instantiate the object in different contexts. It is a nightmare when you need to update the parameters of your constructor as it affects all existing usages. As a result, I would like to introduce the static factory method approach, which can be a better alternative.

#javascript

Static Factory Method: An Alternative to Constructor Overloading in JavaScript
1.30 GEEK