Learn JavaScript INHERITANCE in 7 minutes! 🐇

preview_player
Показать описание
// inheritance = allows a new class to inherit properties and methods
// from an existing class. Helps with code reusability

class Animal{

alive = true;

eat(){
}
sleep(){
}
}

class Rabbit extends Animal{

name = "rabbit";

run(){
}
}

class Fish extends Animal{

name = "fish";

swim(){
}
}

class Hawk extends Animal{

name = "hawk";

fly(){
}
}

const rabbit = new Rabbit();
const fish = new Fish();
const hawk = new Hawk();

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

// inheritance = allows a new class to inherit properties and methods
// from an existing class (parent -> child)
// helps with code reusability

class Animal{

alive = true;

eat(){
console.log(`This ${this.name} is eating`);
}
sleep(){
console.log(`This ${this.name} is sleeping`);
}
}

class Rabbit extends Animal{

name = "rabbit";

run(){
console.log(`This ${this.name} is running`);
}
}

class Fish extends Animal{

name = "fish";

swim(){
console.log(`This ${this.name} is swimming`);
}
}

class Hawk extends Animal{

name = "hawk";

fly(){
console.log(`This ${this.name} is flying`);
}
}

const rabbit = new Rabbit();
const fish = new Fish();
const hawk = new Hawk();

console.log(rabbit.alive);
rabbit.eat();
rabbit.sleep();
rabbit.run();

BroCodez
Автор

Yo bro seriously how do you manage to be such a goat like lord I fricking love your tutorials you make everything look so easy

ArinAkaMazu
Автор

Don't have time to watch as I'm heading out but had to instalike,

Keep at it bro.

SuperFastJewJitsu
Автор

<*_> 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
Автор

❤ waiting for more videos Bro(fourth day)

Gigglesaintlame
Автор

Nice explanation. However, I wonder why you didn't use constructor in any of the classes. Will anything get changed with constructors in inheritance?

manojpatra
Автор

I'm wondering if dev tools have validation features for code inconsistencies like calling a method that doesn't exist or trying to use an unexisting variable/attribute (is there a vscode extension for this?). in Java for example those are detected in compile time, i.e. you need to fix them to get to run the code (the IDE also warns about them to help save time)

helioobianchi
Автор

bro, can you make a video on hashmaps

RedHeadphones
Автор

Bro make a tutorial to download the Java for full stack developer in laptop
Asking for sis

PrAvEeN.__.