0

JavaScript

What is the difference between factory pattern vs constructor pattern ???

18th Mar 2021, 4:06 AM
Mohammad Risad
Mohammad Risad - avatar
2 Answers
0
factory pattern just hide the object creation logic ..so u just call the factory method to create the object..
18th Mar 2021, 4:30 AM
durian
durian - avatar
0
function Constructor() {} function factory() { return new Constructor(); } var obj1 = new Constructor(); var obj2 = factory(); /* factory pattern spare the required use of 'new' before constructor function to create an object... in both above cases, same object kind is returned in obj1 and obj2 (both have same constructors) */
18th Mar 2021, 6:19 AM
visph
visph - avatar