Javascript Prototype Inheritance: A Classy Facade

With the popularity of Object Oriented Programming languages such as Python, Ruby, and Java, many people find the syntax and programmer relation to the code to be highly rewarding. With the massive surge in popularity Javascript has seen over the last decade, many people wanted to see OOP integrated into the functional language. With ES2015 the introduction of classes made its debut and the relation of classes and objects went into full swing. Popular frameworks such as React use classes extensively. However, they have begun to implement Hooks as an alternative to using classes. Debating the benefits and costs of classes and whether or not they should be used in Javascript is not a hill I am ready to die on, so we will move passed that and instead focus on one aspect: classes as defined by OOP languages do not exist in Javascript.

Class methods in Javascript are an extension of prototype inheritance. This is the process of relating difference functions together in a hierarchy, where the further the down the line the function is, the more it stands to inherit. Essentially, any function can be added to this chain to achieve different results. These function form a prototype chain, each function being a link in the chain. When a link is called, the program will start its search at the lowest level and then work its way back up the chain until it finds a matching link, or hits null at the top. Tampering with the prototypes at the highest levels of the chain can create serious performance issues in browsers and is rarely a good idea. The effective top of the chain we are focusing on today is Object.

Object adds syntactic sugar to Javascript allowing for the construction of, you guessed it, objects. Essentially this prototype reformats the functional language features of Javascript into a way that can be easily interpreted by OOP programmers. It does not actually function as an object, it simply looks and responds in a similar way. This has positives and negatives, but ultimately allows alternate methods of processing and using information within Javascript. The basic idea of objects stems from wanting to have built in relationships that grow and expand as the object gets more specific, inheriting properties. This allows for a great deal of flexibility, and can be good to work with. Technically speaking, in prototype inheritance it would be possible to change the what is inherited during each step of inheriting, or even altering specific elements of what gets inherited.

Whether or not you believe that Javascript should strike objects from the record or feel it should go even further toward OOP, there is a sense a wonder and joy that a language can be made so accommodating to the programming world at large. This for the primary language of the web, I believe is pretty exciting. Even if some issues crop up now and again from tacked on syntactic sugar, it creates a flexible language which can be used to do tasks which would prove more challenging for just one side or the other.

A creator to the core, he enjoys all games (especially collaborative ones), baking bread, and software development.