Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.








Object.getType Function

Returns the type of a specified object instance.


var typeVar = Object.getType(instance);





The object to return the type for.


A type instance that represents the run-time object of instance.


Exception Type Condition

argumentUndefined Function

(Debug) instance is undefined.

argumentNull Function

(Debug) instance is null.


Use the getType function to get a new type instance that represents the run-time type of an object.


The following example shows how to use the getType function to create a new type instance that represents the run-time type of an object. It then displays information based on the object type.


<!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">


            // Define and register a Samples.Rectangle class.
            Samples.Rectangle = function(width, height)
                this._width = width;
                this._height = height;

            Samples.Rectangle.prototype.getWidth = function() {
               return (this._width === undefined) ? null : this._width;

            Samples.Rectangle.prototype.getHeight = function() {
               return (this._width === undefined) ? null : this._height;


            // Define and register a Samples.Square class.
            Samples.Square = function(length)
                this._length = length;

            Samples.Square.prototype.getLength = function() {
               return (this._length === undefined) ? null : this._length;

            Samples.Square.prototype.setLength = function(length) {
                this._length = length;


            // Create instances of Square and Rectangle and discover their types.    
            Samples.testObjectReflection = function() 
                var width = 200;
                var height = 100;
                var a = new Samples.Rectangle(width, height);

                var length = 50;
                var b = new Samples.Square(length);

                var name = Object.getTypeName(a);
                // Output "The type name of object a is: Samples.Rectangle"
	            alert("The type name of object a is: " + name);
	            var isSquare = Samples.Rectangle.isInstanceOfType(b)
	            // Output "Object b is an instance of type Square: false"
                alert("Object b is an instance of type Square: " + isSquare);
	            var c = Object.getType(b);
	            name = Object.getTypeName(c);
	             // Output "The type name of object c is: Function"
	            alert("The type name of object c is: " + name);
	            var isSquare = Samples.Square.isInstanceOfType(c);
	            if (isSquare)
	               var newLength = a.getWidth();
	               alert("Object c is a Square with a length of: " + c.getLength());

            // Run the sample.