Condividi tramite


Type.implementsInterface Method

Determines whether a class implements a specified interface type.

var implementsVar = typeInstanceVar.implementsInterface(interfaceType)

Parameters

  • interfaceType
    The interface to test.

Return Value

true if the class implements interfaceType; otherwise, false.

Remarks

Use the implementsInterface method to determine whether a class implements a specific interface. The implementsInterface method verifies both the registered interfaces and registered base class interfaces of the current class.

Description

The following example shows how to use the implementsInterface method to determine whether a class implements a specific interface.

Code

<!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>Samples</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="ScriptManager01">
        </asp:ScriptManager>

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

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

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

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

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

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

            var implementsInterface
            implementsInterface = Samples.C.implementsInterface(Samples.B);
            // Output: "true".
            alert(implementsInterface);

         </script>
    </form>
</body>
</html>

See Also

Reference

Type Class