Test ES6 code for PHPStorm/Babel integration
class Animal {
constructor(name, voice = "says") {
this._name = name;
this._voice = voice;
}
speak(phrase) {
return `${this._name} ${this._voice} ${phrase}.`;
}
}
class Human extends Animal {
constructor(name) {
super(name);
}
speak() {
console.log(super.speak("nothing"));
}
}
class Cat extends Animal {
constructor(name) {
super(name, 'meows');
}
speak() {
console.log(super.speak("hello"));
}
}
class Dog extends Animal {
constructor(name) {
super(name, 'woofs');
}
speak() {
console.log(super.speak("goodbye"));
}
}
const fred = new Human('Fred');
const fluffy = new Cat('Fluffy');
const fido = new Dog('Fido');
[fred, fluffy, fido].forEach(animal => animal.speak());