The JavaScript SUPER keyword is super! 🦸‍♂️

preview_player
Показать описание
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){
}

move(speed){
}
}

class Rabbit extends Animal{

constructor(name, age, runSpeed){
super(name, age);
}

run(){
}
}

class Fish extends Animal{

constructor(name, age, swimSpeed){
super(name, age);
}

swim(){
}
}

class Hawk extends Animal{

constructor(name, age, flySpeed){
super(name, age);
}

fly(){
}
}

const rabbit = new Rabbit("rabbit", 1, 25);
const fish = new Fish("fish", 2, 12);
const hawk = new Hawk("hawk", 3, 50);

Рекомендации по теме
Комментарии
Автор

// 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();

BroCodez
Автор

This cleared up extending classes as a whole. This is what I want from coding tutorials. Just show me the moving parts moving, ! Don't just repeat the same buzzwords as you plow through convoluted examples.

samcheeseboro
Автор

<*_> This is my seal. I have watched the entire video, understood it, and I can explain it in my own words, thus I have gained knowledge. This is my seal. <_*>

piotrmazgaj
Автор

Thanks for the video bro!
Lots of love ❤

hunin
Автор

So I know that this comment don't relate to this video but realy thank you for learning me C#, and I'm writing this comment directly after I finish your course so really thank you too much. ♥

omar.abuissa
Автор

do you mean this is inheritance? nice explanations👌

shashankatole
Автор

hey could you do a tut for a login page with data bank?with install setup and everything

uvpskjh