This is the tiger upper class. All the properties that we are going to define here inside this constructor will be passed or bequeathed to either object that will use this class as a constructor or to subclasses (bengal tigers, siberian tigers) that extend this class.
For example here we are going to define 3 properties that all the Tigers, regardless of species have. Some of them may be common, like the species, which is tiger almost the whole time, but then things change like the color of the fur, the region of living, the color of their eyes, and if they eat meet or not.
Properties are going to be the same but the values not.
Practically:
class Tiger {
constructor(furColor, region, eyeColor, eatMeet) {
this.furColor = furColor;
this.region = region;
this.eyeColor = eyeColor;
this.eatMeet = eatMeet;
this.species = 'Tiger';
}
}
Class Bengal Tiger
Annotations:
This is the Bengal Tiger class. This class inherits all the properties of the tiger class. As we have seen in the example before,this class extends the Tiger class.
Additionally, keep in mind that we want to specify in the super function the values that every Bengal Tiger will have and inherit, and also create the new ones for every unique Bengal Tiger that is going to be created from this subclass afterwards.
So the Bengal Tiger will have a super function inside it's constructor.
Practically that means:
class BengalTiger extends Tiger {
constructor(name, age) {
super('orange-black', 'India', 'gold', true);
this.name = name;
this.age = age;
}
}
Richard Parker
Object
Annotations:
This is the final literal object, that inherits from the Bengal Tiger class. So in order to do it practically we have:
let richardParker = new BengalTiger('Richard Parker', 15);
Jack Sparrow
Object
Annotations:
This is the final literal object, that inherits from the Bengal Tiger class. So in order to do it practically we have:
let jackSparrow= new BengalTiger('Jack Sparrow', 12);
Class SiberianTiger
Annotations:
This is the SiberianTiger class. This class inherits all the properties of the tiger class. As we have seen in the example before,this class extends the Tiger class.
Additionally, keep in mind that we want to specify in the super function the values that every Bengal Tiger will have and inherit, and also create the new ones for every unique Siberian Tiger that is going to be created from this subclass afterwards.
So the Siberian Tiger will have a super function inside it's constructor.
Practically that means:
class SiberianTiger extends Tiger {
constructor(name, age) {
super('white-black', 'Siberia', 'blue', false);
this.name = name;
this.age = age;
}
}
Night's King
Annotations:
This is the final literal object, that inherits from the Siberian Tiger class. So in order to do it practically we have:
let nightKing= new SiberianTiger('Nightking', 1200);
Jon Snow
Annotations:
This is the final literal object, that inherits from the Siberian Tiger class.
So in order to do it practically we have:
let jonSnow= new SiberianTiger('Jon Snow', 25);