Constructor based object creation in Javascript

All object that inherit from another object has a property ‘constructor’ that refers to the constructor of the object. When we use ‘new’, JavaScript injects an implicit reference to the new object being created in the form of the ‘this’ keyword. It also returns this reference implicitly at the end of the function.

Understanding ‘this’ in Javascript

We need a way of identifying and referring to the object that we’re currently working with. When we execute a function, it gets a ‘this’ property, where ‘this’ points to the object which invokes the function. In the following example, ‘this.age’ would point to age property of ‘person’ object.