The Relationship Question: Objects in Javascript

James Ardery
May 17 · 4 min read

The age old story of bootcamp grads is that only once you have completed the bootcamp do you truly realize how much you still don’t know. At Flatiron they crammed HTML, CSS, Ruby, Rails, Javascript, and React into 3.5 months. Smart people spend years / careers on only one of these subjects. In bootcamp we were given 3 weeks to “learn” javascript. This is obviously impossible so there are concessions made. Sacrifice an entire concept due to lack of time. Or address a topic on only a very basic surface level due to lack of time. Now that I am out of bootcamp and going back to javascript to dig a little bit deeper one of the largest sacrifices in the Flatiron curriculum covering javascript is the subject of objects. At Flatiron we were taught that objects are essentially defined with {} curly boys and house key value pairs. The key value pairs are unordered. That was about it…. Oh and that JSON was just one large object. While all of this is true it is very VERY surface. I think things were intentionally kept surface to keep the program moving forward and our fragile brains in tact. Had Flatiron told us that technically an array is an object in Javascript it probably would have made me jump out my window.

Objects in javascript are very versatile and are used in a ton of different ways throughout the language. In many ways I now look at objects as the foundation of javascript. The prototype Object() holds all of the most powerful methods/tools available in javascript. Truly understanding the “this” keyword recognizes that “this” in its most base form represents the foundational window object.

Everything goes back to an object! We use them to build classes. We use them to inherit attributed and methods via the prototype. An array would not be an array if it were not for the object!

Technically and array is an object 😜

The prototype object is how javascript can circumvent lacking classes. Prototype based programming or PBP for short is a way for javascript to mimic object oriented programming (OOP) languages without actually being one! Flatiron taught us javascript after Ruby. In Ruby we were able to create classes and understand blueprints as the relate to OOP languages. The true power of objects in javascript and PBP is unlocked through prototypical inheritance! Here we have 3 different constructor objects. The Shape, the Circle, and the Square. Since both Circle and Square are shapes it would only be fitting to have Shape attributes be inherited by both the Circle and Square objects.

Objects in javascript or any PBP language for that matter are foundational. PBP actually provides a lot of clarity once you get your head wrapped around the role the object plays and how powerful and flexible it is. This flexibility to make quick and easy changes to an objects prototype are a positive when compared to classes in a traditional OOP. When constructing classes a programmer is creating a blueprint. All of the methods and data that need to be associated with that class need to be thought out ahead of time whereas the quick nature of PBP allows a programmer to make changes on the fly. That being said you can get into some trouble messing with the prototype object if you aren’t being careful. Technically PBP gives a programmer the power to alter the functionality of even base JS objects like Arrays or Objects (meta 😶). It doesn’t take much imagination to think up some ways that a programmer could cause a LOT of problems by changing the functionality of something as structural as an array. So this brings me to a rule I picked up from the programmer Mosh Hamedani “Do not modify objects you do not own!”

Gaining a better perspective on objects in javascript has really opened the language up to me. I do realize why this conversation was probably avoided all together in bootcamp. Objects are a little too big in scope for the fragile and fatigued brain of a bootcamp student.

Geek Culture

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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