Type.isInstanceOfType Method

Returns a value that indicates whether an object is an instance of a specified class or of one of its derived classes.

var isInstanceOfTypeVar = TypeA.isInstanceOfType(instance);

Parameters

  • instance
    The object to test.

Return Value

true if instance is an instance of the class; false if instance does not implement the interface, or if it is undefined or null.

Remarks

Use the isInstanceOfType method to determine whether an object is an instance of a specific class.

Example

The following example shows how to use the isInstanceOfType method to determine whether one class is an instance of another 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>Untitled Page</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.A.registerClass('Samples.A');

            Samples.B = function(){}
            Samples.B.registerClass('Samples.B', Samples.A);

            Samples.C = function(){}
            // Register class Samples.C as derived from Samples.A
            Samples.C.registerClass('Samples.C');

            var test;

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

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

            // Output: "false".
            test = Samples.A.isInstanceOfType(Samples.B);
            alert(test)
        </script>
    </form>
</body>
</html>

See Also

Reference

Type Class