Type.initializeBase Method

Initializes the base class and its members in the context of a given instance, which provides the model for inheritance and for initializing base members.

var typeInstanceVar = typeVar.baseClassName.initializeBase(instance, baseArguments );

Parameters

  • instance
    The instance to initialize the base class for. Usually this.

  • baseArguments
    (Optional) The arguments for the base constructor. Can be null.

Return Value

The instance of the base class.

Exceptions

Exception type

Condition

Error.argumentType Function

(Debug) instance is not of the same type as the current instance.

Remarks

Use the initializeBase method to initialize the base class in the context of a given instance. Call initializeBase from the constructor of a class that is derived from a base class. When a derived class instance is instantiated, the initializeBase method is invoked. The instance of the child class inherits the base class object model and its members are initialized.

Example

The following example shows how to create a base class and use the initializeBase method in the constructor of a derived class.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="https://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Sample</title>
</head>
<body>
    <form id="form1" runat="server">
       <asp:ScriptManager runat="server" ID="ScriptManager1">
       </asp:ScriptManager>

       <script type="text/javascript">
        // Register classes to test.
        Type.registerNamespace('Samples');

        Samples.A = function()
        {
            // Initialize as a base class.
            Samples.A.initializeBase(this);
        }

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

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

        Samples.C.registerClass('Samples.C');

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

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

        </script>
    </form>

</body>
</html>

See Also

Reference

Type Class

Other Resources

Language Reference