Simple Class with Extends
by Matthew Day
HTML
<div id="output"></div>
CSS
* {
color: #444;
font-family: 'Arial';
}
JavaScript
var output = document.getElementById('output');
class Animal {
constructor(name) {
this.name = name;
}
}
class Dog extends Animal {
constructor(name, breed) {
super(name);
this.breed = breed;
}
speak() {
const bark = `${this.name} barks to say hello because that\'s what all ${this.breed}\'s do.`;
return bark;
}
}
function fire() {
const promise = new Promise((resolve, reject) => {
const lassie = new Dog('Lassie', 'Rough Collie');
const bark = lassie.speak();
resolve(bark);
});
return promise;
}
fire().then((result) => output.innerHTML = result );