Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
class Animal { constructor(name) { this.name = name; } speak() { return this.name + ' makes a sound'; } } class Dog extends Animal { constructor(name, breed) { super(name); this.breed = breed; } speak() { return super.speak() + ' — Woof!'; } fetch() { return this.name + ' fetches the ball'; } } const rex = new Dog('Rex', 'Labrador'); console.log(rex.speak()); // Rex makes a sound — Woof! console.log(rex.fetch()); // Rex fetches the ball console.log(rex instanceof Dog); // true console.log(rex instanceof Animal); // true
Result
Open