Adobe 27510753 Scripting Guide - Page 80
Operator overloading, MyClass, undefined
UPC - 718659445294
View all Adobe 27510753 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 80 highlights
72 Using ExtendScript Tools and Features Adobe InDesign CS2 Scripting Guide In calling the function, you deconstruct the object you want to pass into a serialized string: myFn (myObject.toSource()); // pass a serialized object 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 (initalValue) { 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 You can override the following operators: Unary Binary +, ~ l The operators > and >= are implemented by executing NOT operator