
CHAPTER 8: ExtendScript Tools and Features Operator overloading 235
Operator overloading
ExtendScript allows you to extend or override the behavior of a math or a Boolean operator for a specific
class by defining a method in that class with same name as the operator. For example, this code defines
the addition (
+) operator for the class MyClass. In this case, the addition operator simply adds the operand
to the property value:
// define the constructor method
function MyClass (initialValue) {
this.value = initialValue;
}
// define the addition operator
MyClass.prototype [“+”] = function (operand) {
return this.value + operand;
}
This allows you to perform the "+" operation with any object of this class:
var obj = new MyClass (5);
Result: [object Object]
obj + 10;
Result: 15
#target name
Defines the target application for this JSX file. The name value is an application
specifier; see Application and namespace specifiers
. Enclosing quotes are optional.
If the Toolkit is registered as the handler for files with the
.jsx extension (as it is by
default), opening the file opens the target application to run the script. If this
directive is not present, the Toolkit loads and displays the script. A user can open a
file by double-clicking it in a file browser, and a script can open a file using a
File
object’s
execute method.
#targetengine
enginename
Defines the target JavaScript engine for this JSX file, within the designated target
application.
Supported by Adobe Illustrator CS5 and Adobe InDesign CS5; other applications
ignore the directive.
X For Adobe Illustrator CS5 and Adobe InDesign CS5, if the named engine does
not exist, and if the script originates within the application (rather than being
executed in the ExtendScript Toolkit or received in an interapplication message),
the application creates a new JavaScript engine with this name, which persists
for the lifetime of the application session.
X If the script originates outside the application, and the named engine does not
exist, the directive is ignored.
Comentarios a estos manuales