Learn JavaScript INHERITANCE in 7 minutes! 🐇
ฝัง
- เผยแพร่เมื่อ 18 พ.ย. 2023
- // inheritance = allows a new class to inherit properties and methods
// from an existing class. 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();
// 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();
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
True ! god bless
Don't have time to watch as I'm heading out but had to instalike,
Keep at it bro.
Amazing job man!
Bro bro bro u a legend ❤❤❤❤❤❤❤
❤ waiting for more videos Bro(fourth day)
Very much good 😂!
Thank you
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)
excellent explanation
thanks bro 😂
bro, can you make a video on hashmaps
Nice explanation. However, I wonder why you didn't use constructor in any of the classes. Will anything get changed with constructors in inheritance?
really a true bro code
We want react js tutorials
👇
Bro make a tutorial to download the Java for full stack developer in laptop
Asking for sis
bro please teach us typeScript