Classes vs Constructors

React is built on a lot of ES6 syntax (an updated and more modern way to write JavaScript) and there are a few more concepts in JavaScript we're learning about before diving into anything else. Some of these concepts are function constructors, inheritance, prototypes, and classes.

From what I understand these don't necessarily come up very often when building apps in React but it is an important concept to understand before moving forward. Essentially, function constructors work like object constructors. They can be seen as a schema, or a model, to be called on later when required. When building a lot of the same type a prototype can be used so that all of its children can inherit its properties. In less vague terms a prototype is exactly what it sounds like - a simply constructed piece that can be cloned over and over but look exactly the same.

Classes on the other hand also seem to be the same exact thing. But prettier! Classes are what is called syntactic sugar for constructors. It is simply a more user-friendly way to create constructors.

Comments