Constructor function vs Factory functions

后端 未结 7 851
清酒与你
清酒与你 2020-11-22 06:52

Can someone clarify the difference between a constructor function and a factory function in Javascript.

When to use one instead of the other?

相关标签:
7条回答
  • 2020-11-22 07:19

    A constructor returns an instance of the class you call it on. A factory function can return anything. You would use a factory function when you need to return arbitrary values or when a class has a large setup process.

    0 讨论(0)
提交回复
热议问题