Gentle Introduction to Prototypes and Prototypal Inheritance in Javascript

In this short video tutorial I will explain in simple terms what are prototypes in Javascript and how Inheritance works.

Key points to keep in mind

  • In Javascript if an object wants to inherit from another object then it can do so using prototypal inheritance.
  • The parent object is referred to as Prototype.
  • __proto__ is deprecated, we can use Object.create()
let fourWheelerObj = {tyres: 4} // Prototype

let carObjectOne = {engine: 'v6', __proto__: fourWheelerObj}

console.log(carObjectOne.tyres) // 4


let carObjectTwo = Object.create(fourWheelerObj)
console.log(carObjectTwo.tyres) // 4

Author: Ankur

I am Enthusiastic about Learning new things and sharing my Knowledge. I like programming and have a pretty good background in Computer Science.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: