tubeshowcase●1,194,391 videos♡ My collection 0
← Learn to Code

Learn to Code07:04

Learn JavaScript INHERITANCE in 7 minutes! 🐇

Bro Code ↗

From the creator

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

Published 2023-11-19 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code