Have you ever seen .prototype attached to an answer in a Stack Overflow post, thought “abort!”, and pressed the back button immediately? Well, you don’t have to worry about this anymore. This article examines what a prototype is, what prototypal inheritance is, and how it can benefit your JavaScript programming greatly.

Why is understanding the prototype, prototypal inheritance, and the prototype chain important?

Understanding prototypal inheritance will help you immensely in making your code clean and simple. Most importantly, it will help you to understand the relationships between objects, how these relationships work under the hood, and the potential that this presents. Furthermore, this knowledge also helps in working with legacy codebases as it’s much more common to see .prototype used in past versions of JavaScript (but that doesn’t make this concept any less important to understand).

What does inheritance mean?

Simply put, you can think of inheritance as an object getting access to the properties and methods of another object. That’s it.

Inheritance is when an object gets access to the properties and methods of another object.

It’s important to note, however, that inheritance in JavaScript is different than inheritance in many other programming languages (such as C## or Java). While these other languages use something called “Classical Inheritance” (friend/protected/private/interface/etc.), JavaScript uses “Prototypal Inheritance”.

#coding #software-development #software-engineering #javascript #programming

JavaScript Under The Hood: Prototype and Prototypal Inheritance
1.05 GEEK