Welcome to JavaScript

Posted by Lester Young on June 6, 2020

“Welcome to JavaScript”. The words that have brought me so much joy and so much pain. For my fourth project I developed a Home Bartender application that lets users share their favorite cocktails. Users, are able to comment, like, and add their own recipes to share with other aspiring at home bartenders. This project was developed with Ruby Active Record in the back end rendered to JSON and sent to the JavaScript front-end.

Going into JS I had to change my train of thought that not all code, runs from top to bottom. When we were developing in Rails, each request would essentially refresh the page. But with JS the page does not refresh and what I learned as “linear” code now has promises and async functions. This was the hardest part in Javascript for me to understand.

Another issue I ran into was how exactly to organize my code. In rails we had specific models and controllers that we would put any actions or functions related to those models in. Moving into object oriented JS we essentially had different classes that we are able to have functions in, but these functions can also be developed in the index.js file. Starting this project I mostly had all my functions in the index.js file. The only thing I had in my class files were the constructors I needed to build for each instance. After making sure I had the program working how I wanted it too, I started moving functions over to their designated classes. This got tricky because there were certain things that I knew belonged in the Recipe class, but not sure what I should leave in index.js. I decided that whatever functions I would have that would affect the DOM I would leave in the Index.js file and everything else I would move to designated classes.

Overall JS is definitely a challenge for me. Up until this part of the course we were mainly learning the ruby language. Which made me realize how lucky and how “magical” the Ruby language is. This project is definitely helped me in learning JS and I am excited to keep learning more!