The JavaScript SUPER keyword is super! 🦸♂️
00:00:00 intro
00:00:22 setup
00:02:39 super constructor
00:05:59 super methods
00:09:03 conclusion
// super = keyword is used in classes to call the constructor or
// access the properties and methods of a parent (superclass)
// this = this object
// super = the parent
class Animal{
constructor(name, age){
this.name = name;
this.age = age;
}
move(speed){
console.log(`The ${this.name} moves at a speed of ${speed}mph`);
}
}
class Rabbit extends Animal{
constructor(name, age, runSpeed){
super(name, age);
this.runSpeed = runSpeed;
}
run(){
console.log(`This ${this.name} can run`);
super.move(this.runSpeed);
}
}
class Fish extends Animal{
constructor(name, age, swimSpeed){
super(name, age);
this.swimSpeed = swimSpeed;
}
swim(){
console.log(`This ${this.name} can swim`);
super.move(this.swimSpeed);
}
}
class Hawk extends Animal{
constructor(name, age, flySpeed){
super(name, age);
this.flySpeed = flySpeed;
}
fly(){
console.log(`This ${this.name} can fly`);
super.move(this.flySpeed);
}
}
const rabbit = new Rabbit("rabbit", 1, 25);
const fish = new Fish("fish", 2, 12);
const hawk = new Hawk("hawk", 3, 50);
rabbit.run();
fish.swim();
hawk.fly();
-
7:14:53
Delnorin Games
13 hours ago🔴 Live - CitizenCon 2954 Day 2 - Rumble Watch Party
59.4K2 -
1:06:57
The Breanna Morello Show
1 day ago $7.70 earnedLIVE STREAM: Going LIVE Sunday at 10am ET
42.9K21 -
51:47
Criminal Content
19 hours agoPREDATOR (1987) Movie Reaction w/ Coby FIRST TIME WATCHING
44K22 -
13:52
Misha Petrov
21 hours agoSmile 2 Review + Movie Breakdown
42.1K16 -
49:24
hickok45
12 hours agoSunday Shoot-a-Round # 251
49.5K26 -
11:04
Bearing
8 hours agoMan FAKED Being FAKE Woman - They/Them Community OUTRAGED!
48.5K48 -
8:21
scoutthedoggie
1 day agoAirsoft War Stoner 63 Scotland
50.9K6 -
3:30
SeasonofMist
22 days agoSARAH LONGFIELD - Cataclysm (Official Music Video/Play-Through)
30.7K4 -
2:15
LimitlessAmbition
1 day ago $1.98 earnedOVERCOME Obstacles with Ancient Stoic WISDOM
21.8K2 -
1:03:17
Standpoint with Gabe Groisman
1 day agoEP. 55. Paying the Ultimate Price. Dr Yechiel Leiter
25K4