Private Fields Development Tutorials, Guides & Insights
Unlock 1+ expert-curated private fields tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your private fields skills on DeveloperBreeze.
Adblocker Detected
It looks like you're using an adblocker. Our website relies on ads to keep running. Please consider disabling your adblocker to support us and access the content.
Understanding JavaScript Classes
class Animal {
constructor(type, name) {
this.type = type;
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
class Dog extends Animal {
constructor(name, breed) {
super('Dog', name);
this.breed = breed;
}
speak() {
console.log(`${this.name} barks.`);
}
}
const dog = new Dog('Buddy', 'Golden Retriever');
dog.speak(); // Output: Buddy barks.The super keyword is used to call the constructor or methods of the parent class. This is particularly useful when you need to add functionality to a subclass while still retaining the behavior of the parent class.