Export (0) Print
Expand All

constructor Property

Specifies the function that creates an object.

object.constructor

Arguments

object
Required. The name of an object or function.

Remarks

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.

Example

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.

Requirements

Version 2

See Also

prototype Property

Applies To: Array Object | Boolean Object | Date Object | Function Object | Number Object | Object Object | String Object

Show:
© 2014 Microsoft