Because there are methods to register namespaces, classes,
interfaces, and enumerations, there also exists the ability to perform
reflection similar to the System.Reflection namespace in .NET. I used the
following code to create a string message, checking whether specific objects
were of the specified type. I'll explain each below:
Listing 17
var classInstance = new Nucleo.MyClass();
var msg = "isNamespace(Nucleo) = " + Type.isNamespace(Nucleo);
msg += "\nisClass(Nucleo.MyClass) = " + Type.isClass(Nucleo.MyClass);
msg += "\nisClass(classInstance) = " + Type.isClass(classInstance);
msg += "\nisInterface(Nucleo.MyInterface) = " + Type.isInterface(Nucleo.MyInterface);
msg += "\nisInterface(classInstance) = " + Type.isInterface(classInstance);
msg += "\nimplementsInterface(Nucleo.MyClass) = " +
Type.implementsInterface(Nucleo.MyClass);
alert(msg);
Each of these checks whether the object is of a specified
type, by using the Type.is<Type> methods. However, these methods do not
work for class instances, but rather inspect the actual type name itself. In
my methods above, anywhere classInstance is used, a false value was returned.