JScript 8.0 中文手册| 首页 | asp之家
constructor 属性

指定创建一个对象的函数。

object.constructor
参数
object

必选。对象或函数的名称。

备注

constructor 属性是每个具有原型的对象的原型成员。这包括除了 argumentsEnumeratorErrorGlobalMathRegExpRegular ExpressionVBArray 对象以外的所有内部 JScript 对象。constructor 属性包含了对某种函数的引用,此种函数构造了特定对象的实例。

基于类的对象没有 constructor 属性。

示例

下面的示例阐释了 constructor 属性的用法。

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);

该程序的输出为:

Object is a String.
Object is constructed from MyFunc.
要求

版本 2

请参见

参考

prototype 属性