JavaScript » Object » constructor

Syntax:
Object.constructor

This specifies a function to create an object's property and is inherited by all objects from their prototype.

A constructor property is inherited by all objects from their prototype. It is this fact that allows you to create a new instance of an object using the new operator. If you display the constructor property of any object, you see the construction of the function that created it.

Examples

Code:
document.write(Cat.constructor)
Output:
function Cat(breed, name, age) { this.breed = breed this.name = name
this.age = age }
Explanation:

Assuming the existence of an object called 'Cat', this code would display that function.

Code:
if(Sheeba.constructor == Cat)
   document.write("This is an instance of 'Cat'.")
Explanation:

The constructor property can also be used to compare two objects (including those, such as documents and forms, that cannot be constructed). This example compares the 'Sheeba' object with the 'Cat' object to see if it is an instance of it.