+ 1
What is the factory function in java script?
2 Respostas
+ 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.
+ 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.