Do you know why we often create objects with factories rather than classes?

I did not. As a backend developer forced to write JS during a fullstack freelance gig, I wrote factories because “that’s how the other code looked”.

Now that’s a terrible reason. The differences are simple, and a basic understanding will save you headaches.

In a nutshell, a factory is a function that returns an object, while a class is a template for an object.

But let’s walk through an example of a RocketShip class to understand how behaviour differs.

#programming #coding #javascript

Why Factories are better than Classes in JavaScript
4.50 GEEK