Let’s create a “Reptile” object, that has two properties: type, and age. On that object we’ll have setter functions for both properties, and while we’re at it, let’s say the type will be some custom enumeration as defined below.
Let’s look at the class implementation of our Reptile class, post ECMAScript 2015, just for reference:
This is pretty simple, we have a Reptile class that has an empty constructor function to instantiate. Next, within the class definition we can set two methods: setAge(), and setType(), which do exactly what they sound like they do.
Now, let’s look at the prototype implementation - pre ECMAScript 2015 (and what the class definition pretty much does in the background.
This is a very basic example, but I always find it fun to look into how things were done before new improvements in development came around.