Compartir a través de


constructor Property (Windows Scripting - JScript)

 

Specifies the function that creates an object.

Syntax

object.constructor

Remarks

The required object is 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 Global and Math objects. The constructor property contains a reference to the function that constructs instances of that particular object.

The following example illustrates the use of the constructor property.

function testObject(ob)
{
    if (ob.constructor == String)
        return ("Object is a String.");
    else if (ob.constructor == MyFunc)
        return ("Object is constructed from MyFunc.");
    else
        return ("Object is neither a String nor constructed from MyFunc.");
}

// A constructor function.
function MyFunc() {
    // Body of function.
}

var x = new String("Hi");
document.write(testObject(x));
document.write ("<br />");

var y = new MyFunc;
document.write(testObject(y));

The output of this program is as follows.

Object is a String.
Object is constructed from MyFunc.

Requirements

Version 2

Applies To: Array Object (Windows Scripting - JScript)| Boolean Object (Windows Scripting - JScript)| Date Object (Windows Scripting - JScript)| Function Object (Windows Scripting - JScript)| Math Object (Windows Scripting - JScript)| Number Object (Windows Scripting - JScript)| Object Object (Windows Scripting - JScript)| String Object (Windows Scripting - JScript)

Change History

Date

History

Reason

March 2009

Modified example.

Content bug fix.

See Also

prototype Property (Windows Scripting - JScript)