JavaScript: Prototype VS Classes
Published on October 15th, 2019
JavaScript: Prototype VS Classes
Source: https://medium.com/@parsyval/javascript-prototype-vs-class-a7015d5473b
Object / Prototype
- Constructor-like function
- Use of New to add instance of the prototype
- Objects inherit from other objects
- The custom one inherit from higher generic Object
- Has __proto__ object with function
- Created Instances are REFERENCES to the Prototype - changing the __proto__ of an object, changes the class and all objects
Class
- ES6 Classes are 'syntactic sugar' for Prototypes
- It has extends, constructor, super, static classes
- But still uses __proto__ underneath the hood and is based on references
- A Class is of type function