ES6 did introduce a syntax for object creation that uses the
class keyword. Although this is a new syntax it does the same thing as the
object constructors and
prototypes we have learned about in previous topics. Therefore in this topic you only need to learn about the new syntax.
If you want to use classes in your code, which is fine, you can use them much the same way as object constructors.
What are classes in js?
Classes syntax in js
- Class declaration
- Class expression
The differences between using a class to define a constructor and other prototype methods
What "getters" & "setters" are
The conflict in JS with functional programming and classes
This article is probably just about all you need to start using
classsyntax confidently. "Getters and Setters" are a useful feature!
The MDN docs are, as usual, a great resource for going a little deeper. Look especially at the ‘extends’ and ‘Mixins’ sections. React (and other frameworks) uses classes in this way. In other words, you create your components and make them
extendthe core React component. In that way you have access to all their built-in functionality.