This documentation is archived and is not being maintained.

constructor Property 

Specifies the function that creates an object.


object.constructor

object

Required. The name of an object or function.

The constructor property is a member of the prototype of every object that has a prototype. This includes all intrinsic JScript objects except the arguments, Enumerator, Error, Global, Math, RegExp, Regular Expression, and VBArray objects. The constructor property contains a reference to the function that constructs instances of that particular object.

Class-based objects do not have a constructor property.

The following example illustrates the use of the constructor property.

function testObject(ob) {
   if (ob.constructor == String)
      print("Object is a String.");
   else if (ob.constructor == MyFunc)
      print("Object is constructed from MyFunc.");
   else
      print("Object is neither a String or constructed from MyFunc.");
}
// A constructor function.
function MyFunc() {
   // Body of function.
}

var x = new String("Hi");
testObject(x)
var y = new MyFunc;
testObject(y);

The output of this program is:

Object is a String.
Object is constructed from MyFunc.
Show: