Skip to content

extendscript-reflection-interface

ExtendScript provides a reflection interface that allows you to find out everything about an object, including its name, a description, the expected data type for properties, the arguments and return value for methods, and any default values or limitations to the input values.


Every object has a reflect property that returns a Reflection Object that reports the contents of the object. You can, for example, show the values of all the properties of an object with code like this:

var f = new File ("myfile");
var props = f.reflect.properties;
for (var i = 0; i < props.length; i++) {
$.writeln('this property ' + props[i].name + ' is ' + f[props[i].name]);
}

All properties are read only.

reflect.description

Short text describing the reflected object, or undefined if no description is available.

String


reflect.help

Longer text describing the reflected object more completely, or undefined if no description is available.

String


reflect.methods

An Array of ReflectionInfo object containing all methods of the reflected object, defined in the class or in the specific instance.

Array of ReflectionInfo objects


reflect.name

The class name of the reflected object.

String


reflect.properties

An Array of ReflectionInfo object containing all properties of the reflected object, defined in the class or in the specific instance. For objects with dynamic properties (defined at runtime) the list contains only those dynamic properties that have already been accessed by the script.

For example, in an object wrapping an HTML tag, the names of the HTML attributes are determined at run time.

Array of ReflectionInfo objects


reflectionObj.find(name)

Returns the ReflectionInfo object for the named property of the reflected object, or null if no such property exists.

Use this method to get information about dynamic properties that have not yet been accessed, but that are known to exist.

ParameterTypeDescription
nameStringThe property for which to retrieve information.

This code determines the class name of an object:

obj = new String ("hi");
obj.reflect.name; // => String

This code gets a list of all methods:

obj = new String ("hi");
obj.reflect.methods; //=> indexOf,slice,...
obj.reflect.find ("indexOf"); // => the method info

This code gets a list of properties:

Math.reflect.properties; //=> PI,LOG10,...

This code gets the data type of a property:

Math.reflect.find ("PI").type; // => number

This object contains information about a property, a method, or a method argument.

You can access ReflectionInfo objects in a Reflection object’s properties and methods arrays, by name or index:

obj = new String ("hi");
obj.reflect.methods[0];
obj.reflect.methods["indexOf"];

You can access the ReflectionInfo objects for the arguments of a method in the arguments array of the ReflectionInfo object for the method, by index:

obj.reflect.methods["indexOf"].arguments[0];
obj.reflect.methods.indexOf.arguments[0];

obj.reflect.methods[0].arguments

For a reflected method, an array of ReflectionInfo objects describing each method argument.

Array of ReflectionInfo objects


obj.reflect.methods[0].dataType

The data type of the reflected element.

String. One of:

  • "boolean"
  • "number"
  • "string"
  • "Classname": The class name of an object. !!! note Class names start with a capital letter. Thus, the value String stands for a JavaScript string, while String is a JavaScript String wrapper object.
  • *: Any type. This is the default.
  • null
  • undefined: Return data type for a function that does not return any value.
  • unknown

obj.reflect.methods[0].defaultValue

The default value for a reflected property or method argument, or undefined if there is no default value, if the property is undefined, or if the element is a method.

Any


obj.reflect.methods[0].description

Short text describing the reflected object, or undefined if no description is available.

String


obj.reflect.methods[0].help

Longer text describing the reflected object more completely, or undefined if no description is available.

String


obj.reflect.methods[0].isCollection

When true, the reflected property or method returns a collection; otherwise, false.

Boolean


obj.reflect.methods[0].max

The maximum numeric value for the reflected element, or undefined if there is no maximum or if the element is a method.

Number


obj.reflect.methods[0].min

The minimum numeric value for the reflected element, or undefined if there is no minimum or if the element is a method.

Number


obj.reflect.methods[0].name

The name of the reflected element. A string, or a number for an array index.

String or Number


obj.reflect.methods[0].type

The type of the reflected element.

String. One of:

  • readonly: A Read only property.
  • readwrite: A read-write property.
  • createonly: A property that is valid only during creation of an object.
  • method: A method.