1

I am struggling with the concept of modules, factory functions, and constructors...

I am the most curious about the difference between module and factory function, and when to use what?

  • A module is essentially a singleton, while a factory function can be used multiple times. (If the factory function is called only once, the lines blur… but the `function` is the factory and the returned object is the module). – Bergi Aug 14 '20 at 19:37

1 Answers1

2

The main difference between modules and factory functions are simpler than you think.

Modules are just files with blocks of code that you can import/export.

Whereas factory functions are functions that create objects and return them. Also you might find this other stack overflow post that explains constructor functions vs factory functions:

Constructor function vs Factory functions

ByteTheBits
  • 179
  • 1
  • 4
  • 11
  • "*Modules are just files*" - you seem to refer to ES6 modules here? There are other things for which the term "module" is used. – Bergi Aug 14 '20 at 19:36