Type.implementsInterface Method
Determines whether a class implements a specified interface type.
Syntax
var implementsVar = typeInstanceVar.implementsInterface(interfaceType)
-
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
JavaScript
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://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>