So you might be wondering what is subclassing. First lets get to the root prefix 'sub'. The origin of this word dates all the way back to the Latin language and you may be surprised when you hear the Latin equivalent. Any takers? Well if you guessed 'sub' than you are correct! Hah! They are literally the same word and this prefix means below. Just like a submarine goes below the water or a subway runs beneath the ground. So when we apply this to computer science, a subclass would mean a class beneath another class.
So here I created a constructor function called SupDude and I put the properties inside my constructor using the 'this' keyword. I also added a whatsUp method straight to my constructor's prototype outside of the constructor. Lets take a look at what creating an instance of this supDude object in the console would look like.
You can see that I used the 'new' keyword to create my supDude object and it has the property of chill that was named inside the constructor. Now lets see what creating a subclass would look like.
Here I created a YoBro constructor and used SupDude.call(this) to inherit the properties from SupDude. I also made sure YoBro points to SupDude's prototype to ensure YoBro inherits SupDude's methods as well. This was done by YoBro.prototype = Object.create(SupDude.prototype). I also made sure YoBro retains its own constructor and this was done with YoBro.prototype.constructor = YoBro. Now lets take a look at this in action in the console.
You can see that when I enter YoBro.prototype it is pointing to SupDude's prototype.
Here I create an instance of YoBro called yaBoi. You can see that yaBoi inherited the 'chill' and 'dude' properties from SupDude along with the 'whatsUp' method. yaBoi also has its distinct property of 'bro' and its own method 'hollah'. Therefore making it a subclass of SupDude.