The current project, Node Hangman, is an exercise in building constructors that can be exported. The directions specifically requested to use as many constructors as possible, just as a proof that we know how to use them.

A Brief History

As someone who grew up with PHP, I like having classes in my objects. I’ve learned that Javascript is not actually an Object Oriented Language, as its inheritance is completely different and the prototype method means a consistent schema isn’t actually required from instance to instance. But as a student who is familiar with a traditional OOP ideas, I created several functions in my modules that generally wouldn’t be included in a constructor prototype.

Node Hangman Code
I mean, seriously. Why is this inside a constructor?

As the project moved on, I found the easiest way to use the main constructors (Word, which creates and displays the selected puzzle, and GameControl, which affects the flow, actions, and status of the game) was actually to pass the main instance within almost every module function. Most of the functions inside GameControl require you to pass in currentWord (the Word object of the current puzzle) and controls (the GameControl of the current game).

Doing so solved all of the problems I was having with the keyword this. It works because I only have one GameControl and one Word.

Writing Solid Code

When I was nearly completed with the working project, I read an article explaining SOLID code vs. STUPID code. It basically rips my project to pieces and recognizes it as terrible code. Any change in one of the 2 constructors will require significant changes in the other. Each constructor actually does too much, as there is not much of a separation of concerns. My variables are all listed as var instead of including let and const where it would be more appropriate.

My only defense is that the project works as intended, and it satisfies the requirements of the project. Moving forward, I’ll be focusing on creating significantly more SOLID code!