Why bother with all the caveats of constructor in JavaScript if you can write a factory function that will return an object instead? It has got the same effect, but skips new insanity. This is how simple it is:

The trick with instanceof is clever, but due you really need such tricks all over the place?

I’ve presented factory pattern and other useful ones in my post https://levelup.gitconnected.com/oop-best-practices-that-are-anti-patterns-in-functional-javascript-61ee1af35452

--

--

--

Father. Husband. Solutions developer profesionally (software quite often). Arsenal supporter. Cyclist.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adam Brodziak

Adam Brodziak

Father. Husband. Solutions developer profesionally (software quite often). Arsenal supporter. Cyclist.

More from Medium

Array Fundamentals in JavaScript

Comparing Data Structures: Arrays vs Objects

Different methods to merge objects in JavaScript

Basics of JavaScript and Version Controlling