Export (0) Print
Expand All

Type Class

Provides a typing and type-reflection system for ECMAScript (JavaScript) object-oriented programming functionality.

Namespace: None. The Type methods are global and not part of a namespace.

Inherits: window.

Type.registerNamespace( string );

Name

Description

Type.callBaseMethod Method

Invokes a base class method with specified arguments.

Type.createCallback Method

Creates a callback method, given the function to callback and the parameter to pass to it.

Type.createDelegate Method

Creates a delegate function that keeps the context from its creation. The context defines the object instance to which the this keyword points.

Type.getBaseMethod Method

Returns the implementation of a method from the base class of the specified instance.

Type.getBaseType Method

Returns the base type of an instance.

Type.getInterfaces Method

Returns an Array object that contains the list of interfaces that the type implements.

Type.getName Method

Returns the name of the instance type.

Type.getRootNamespaces Method

Returns an Array object that contains references to all the root namespaces of the client application.

Type.implementsInterface Method

Determines whether the type implements a specified interface.

Type.inheritsFrom Method

Determines whether the type inherits from the specified parent type.

Type.initializeBase Method

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

Type.isClass Method

Returns a value that indicates whether the specified type is a class.

Type.isEnum Method

Indicates whether the specified type is an enumeration.

Type.isFlags Method

Get a value that indicates whether the specified type is an integer of flags.

Type.isImplementedBy Method

Determines whether an instance implements the specified interface.

Type.isInstanceOfType Method

Determines whether an object is an instance of either a specified type or of one of its derived types.

Type.isInterface Method

Returns a value that indicates whether the specified type is an interface.

Type.isNamespace Method

Returns a value that indicates whether the specified object is a namespace.

Type.parse Method

Returns an instance of the type that is specified by a type name.

Type.registerClass Method

Registers a class that is defined by the constructor, with an optional base type and with interfaces.

Type.registerEnum Method (ASP.NET AJAX)

Registers an enumeration.

Type.registerInterface Method

Registers an interface that is specified by its constructor.

Type.registerNamespace Method

Registers and creates a namespace.

Type.resolveInheritance Method

Copies members from the base class to the prototype that is associated with the derived class, and continues this process up the inheritance chain. This enables you to reflect on the inherited members of a derived type.

The methods of the Type class add object-oriented programming functionality to ECMAScript (JavaScript) code by creating a typing system and by enabling type reflection. This class enables you to register code relationships and structure, which includes classes, interfaces, base classes, and enumerations. You can use the Type reflection methods such as isInstanceOfType and isImplementedBy for inspecting classes. The built-in JavaScript Function object is aliased to Type. Therefore, many of the Type methods are available for your own custom type objects created through the Type APIs.

For an overview of the object-oriented programming model in Microsoft AJAX Library, see Creating Custom Client Script by Using the Microsoft AJAX Library.

Deriving From a Base Class

The Type methods support only single inheritance but allow multiple interfaces. Derive one class from another by following these steps:

  • When you register the derived class, specify a base class in the baseType parameter of the registerClass method.

  • Initialize the derived class's base by invoking the initializeBase method from the constructor of the derived class.

Calling a Base Class Method From a Derived Class Member

You call base class methods from derived class members by invoking the Type.callBaseMethod method. You do this when you want to override methods. For example, you call the base class if you override the Sys.Component.dispose method in a derived class.

The following code shows how to register a class that is derived from a base class. You call the registerClass method of the type that is being registered. The base class is specified in the baseType parameter. The derived class initializes its base class by calling the initializeBase method from its constructor.

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);

Implementing an Interface

The Microsoft AJAX Library Type methods support interfaces. You implement an interface when you call the registerClass method by specifying a registered interface in the interfaceTypes parameter. For more information about registering an interface, see Type.registerInterface Method.

The following example shows how to create a derived class that implements an interface. The code invokes the registerClass method with a base class specified in the baseType parameter and an interface specified in the interfaceTypes parameter. The base class is initialized in the context of a given instance by invoking initializeBase from the constructor of the derived class. The implementsInterface method is then called to determine the interface of a class instance.

Community Additions

ADD
Show:
© 2014 Microsoft