Alih -alih membuat duplikat properti setiap kali, kami dapat dengan mudah menambahkan properti ke prototipe, karena semua contoh memiliki akses ke objek prototipe.
class Dog {
constructor(name) {
this.name = name;
}
bark() {
return `Woof!`;
}
}
const dog1 = new Dog("Daisy");
const dog2 = new Dog("Max");
const dog3 = new Dog("Spot");
Dog.prototype.play = () => console.log("Playing now!");
dog1.play();
Foolish Flamingo