extendscript-reflection-interface
ExtendScript Reflection Interface
Section titled “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.
ReflectionObject
Section titled “ReflectionObject”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]);}
ReflectionObject Attributes
Section titled “ReflectionObject Attributes”All properties are read only.
description
Section titled “description”reflect.description
Description
Section titled “Description”Short text describing the reflected object, or undefined if no description is available.
String
reflect.help
Description
Section titled “Description”Longer text describing the reflected object more completely, or undefined
if no description is available.
String
methods
Section titled “methods”reflect.methods
Description
Section titled “Description”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
Description
Section titled “Description”The class name of the reflected object.
String
properties
Section titled “properties”reflect.properties
Description
Section titled “Description”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
ReflectionObject Methods
Section titled “ReflectionObject Methods”find()
Section titled “find()”reflectionObj.find(name)
Description
Section titled “Description”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.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
name | String | The property for which to retrieve information. |
Examples
Section titled “Examples”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
ReflectionInfo Object
Section titled “ReflectionInfo Object”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];
ReflectionInfo Attributes
Section titled “ReflectionInfo Attributes”arguments
Section titled “arguments”obj.reflect.methods[0].arguments
Description
Section titled “Description”For a reflected method, an array of ReflectionInfo objects describing each method argument.
Array of ReflectionInfo objects
dataType
Section titled “dataType”obj.reflect.methods[0].dataType
Description
Section titled “Description”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 valueString
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
defaultValue
Section titled “defaultValue”obj.reflect.methods[0].defaultValue
Description
Section titled “Description”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
description
Section titled “description”obj.reflect.methods[0].description
Description
Section titled “Description”Short text describing the reflected object, or undefined
if no description is available.
String
obj.reflect.methods[0].help
Description
Section titled “Description”Longer text describing the reflected object more completely, or undefined
if no description is available.
String
isCollection
Section titled “isCollection”obj.reflect.methods[0].isCollection
Description
Section titled “Description”When true
, the reflected property or method returns a collection; otherwise, false
.
Boolean
obj.reflect.methods[0].max
Description
Section titled “Description”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
Description
Section titled “Description”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
Description
Section titled “Description”The name of the reflected element. A string, or a number for an array index.
String or Number
obj.reflect.methods[0].type
Description
Section titled “Description”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.