This documentation is archived and is not being maintained.

Type.registerClass Method

Visual Studio 2008

Registers a class as defined by a constructor with an optional base type and interface type.

classInstanceVar.registerClass(typeName, baseType, interfaceTypes)


A string that represents the fully qualified name of the type.


(Optional) The base type.


(Optional) An unbounded array of interface type definitions that the type implements.

The registered type.

Exception type


Error.argument Function

(Debug) typeName cannot be evaluated.


(Debug) baseType is not a class.

Error.invalidOperation Function

(Debug) The class specified by typeName is already registered.

Use the registerClass method to register a class as defined by a constructor with an optional base class and interface type. The registerClass method is invoked after the class has been defined, but before it is instantiated. The registerClass method is invoked directly from the class.

Deriving from a Base Class

Methods of the Sys.Type class support single inheritance. You derive one class from another by following these steps:

  • When you register the derived class, specify a base class in the baseType parameter of the registerClass method.

  • In the first line of the derived class definition, initialize the base class by calling the Type.initializeBase method.

The following example shows how to register a class that is derived from a base class. The code invokes the registerClass method with a base class specified in the baseType parameter. The derived class initializes its base class by calling the Type.initializeBase method in the first line of its definition.


Samples.A = function(){}
// Register Samples.A Class

Samples.B = function(){}
// Register Samples.B Class

Samples.C = function(){
    // Initialize the base.
// Register Samples.C Class as derviving from Samples A and implementing Samples.B
Samples.C.registerClass('Samples.C', Samples.A, Samples.B);

Implementing an Interface

Methods of the Type class support implementing an interface. You implement an interface by specifying a registered interface in the interfaceTypes parameter of the registerClass method when you register the class. For more information about how to register an interface, see Type.registerInterface Method.

The following example shows how to register a derived class. The registerClass method specifies a base class in the baseType parameter.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head id="Head1" runat="server">
    <form id="form1" runat="server">
       <asp:ScriptManager runat="server" ID="ScriptManager1">

       <script type="text/javascript">
        // Register classes to test.

        Samples.A = function()
            // Initialize as a base class.

        Samples.B = function(){}
        Samples.C = function(){}

        Samples.B.registerClass('Samples.B', Samples.A);


        var isDerived;
        isDerived = Samples.B.inheritsFrom(Samples.A);
        // Output: "true".

        isDerived = Samples.C.inheritsFrom(Samples.A);
        // Output: "false".