Prototypal Classes
A prototypal class with Object.create(..)
-
All functions by default reference an empty object at a property named
prototype
. -
This is not the function’s prototype (where the function is prototype linked to), but rather the prototype object to link to when other objects are created by calling the function with
new
. -
So you could do this instead:
- The “prototypal class” pattern is now strongly discouraged, in favor of using ES6’s class mechanism:
- Under the covers, the same prototype linkage is wired up, but this class syntax fits the class-oriented design pattern much more cleanly than “prototypal classes”.