Constructor function vs Factory functions

后端 未结 7 993
清酒与你
清酒与你 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 06:55

    For the differences, Eric Elliott clarified very well,

    But for the second question:

    When to use one instead of the other?

    If you are coming from the object-oriented background, Constructor function looks more natural to you. this way you shouldn't forget to use new keyword.

提交回复
热议问题