Object Inheritance and Prototype chaining
Two Different Data Types
- Primitive values
- Non-primitive values (object references)
- Wrappers for numbers, Boolean and Strings
Objects such as functions and arrays are referred to as non-primitive values
The fundamental difference between those two mentioned above is that
primitives are: not mutable and non-primitive are: mutable.
Everthing else that is not primitives falls into objects
Now in ES5 we have a constructor/prototype functionsFor Example, a Constructor Person can have many different instances as per the picture below. Here the constructor is a blueprint with its parameters defined and the rest of the instances that are objects can use and access all of this from the constructor.
Inheritance — the ES5 way
While classes are just icing sugar over ES5, we must know how actually inheritance is implemented in ES5. This is why I created a course from scratch so you can learn from the basics. When it comes to inheritance, the only important thing to understand this example so we have for example Person Constructor and Administrator, which will be an instance of the Perso. Now in Person, we define the basic parameters and methods that are relevant to the each and every person. In the Administrator, we define its own methods and parameters but what is important in Inheritance we can access those methods, properties from the Person and that is less code, cleaner design and ect.
Inheritance — With Prototype Property
That is all for now I will link here another post to the ES6 and you will be able to see the difference between ES5