class Hero {
constructor(name, side) {
this.name = name;
this.side = side;
}
speak() {
return "<p>My name is " + this.name +
", I'm with the " + this.side + ".</p>";
}
}
var darkVador = new Hero("Dark Vador", "empire");
var luke = new Hero("Luke Skywalker", "rebels");
var ianSolo = new Hero("Ian Solo", "rebels");
function makeHeroesSpeak() {
document.body.innerHTML += darkVador.speak();
document.body.innerHTML += luke.speak();
document.body.innerHTML += ianSolo.speak();
}
JS.Objects.Classes.JavaScript OOP: a simple ES6 class
------------------------------------------------------
A [Pen](https://codepen.io/Onlyforbopi/pen/ZMgLOy) by [Pan Doul](https://codepen.io/Onlyforbopi) on [CodePen](https://codepen.io).
[License](https://codepen.io/Onlyforbopi/pen/ZMgLOy/license).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript OOP: create objects with an ES6 class</title>
</head>
<body>
<p>Look at the JS code. This time we created multiple objects using an ES6 class named Hero.</p>
<p>
<button onclick='makeHeroesSpeak();'>Make Star Wars heroes speak!</button>
</p>
</body>
</html>