constructor Property

When an object is created, a special property is assigned to it behind the scenes-the constructor property. It contains a reference to the constructor function used to create this object.

Continuing from the previous example:

h2.constructor

Hero(name)

The constructor property contains a reference to a function. You can call this function to produce a new object.

var h3 = new h2.constructor('Rafaello');

h3.name;
"Rafaello"
>

If an object was created using the object literal notation(), its constructor is the built-in Object() constructor function.

var o = {};

o.constructor;
Object()

typeof o.constructor;
"function"
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +