JavaScript tutorial:
constructor property

 

Applies to: Array Object, Boolean Object, Date Object, Function Object, Math Object, Number Object, Object Object, String Object

The constructor property is specifies the function that creates an object.

Syntax

object.constructor

The required object argument is the name of an object or function.

Example

The constructor property is a member of the prototype of every object that has a prototype. This includes all intrinsic JavaScript objects except the Global and Math objects. The constructor property contains a reference to the function that constructs instances of that particular object. For example:

x = new String("Hi");
if (x.constructor == String)
{
// Do something (the condition will be true).
document.write("My name is Henry.");
}

or

function MyFunc()
{
var s="Hello world!";
return(s);
}
y = new MyFunc();
if (y.constructor == MyFunc)
document.write("Antechinus JavaScript Editor");

  To run the code above, paste it into JavaScript Editor, and click the Execute button

See also: prototype Property