+ 1

What is the factory function in java script?

14th Mar 2019, 7:06 PM
Ramniwas Kumawat
Ramniwas Kumawat - avatar
2 odpowiedzi
+ 3
//A factory function is any function which is not a class or constructor that returns a (presumably new) object. In JavaScript, any function can return an object. When it does so without the new keyword, it's a factory function.
14th Mar 2019, 7:32 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 1
When a function returns an object, we call it factory function. You may have look on example below: function solo() { return { name: 'SoloLearn', type: 'app', id: 00000 }; } Each time we call this factory, it will return a new instance of the solo object.
14th Mar 2019, 7:36 PM
Rakibul Yeasin
Rakibul Yeasin - avatar