Illustrator (Desktop) SDK/Scripting Issues
1 result found
-
Bug: JavaScript unary operators "+" and "-" do not function as documented for UnitValue objects
According to the Illustrator ExtendScript documentation, applying the unary operators "+" or "-" to a UnitValue object should respectively produce the numeric value or the negated numeric value of the UnitValue. However, they instead respectively produce the UnitValue unmodified or the UnitValue with its value negated.
Either the documentation or the behaviour should be updated to reflect the other.
I observed this behaviour in Illustrator 28.5 on Mac OS Sonoma.
The behaviour may be quickly tested with the following script:
var uv = new UnitValue(2, "px");
alert(
"Results:" +
"\nUnitValue unmodified: \"" + uv + "\" (" + (typeof uv)…3 votesNihiltres, UnitValue is an object with properties
baseUnit - type of UnitValue data type
type - type of String data type
value - type of Numeric data type.
When using unary operator on object, the underlying value property of the object is modified.
Example:
var uv = new UnitValue(2, "px");
"-uv" will result in uv.value modified from "2" to "-2" and stays as Numeric data type.
Any unary operator on object as whole will return the object itself.
Alternatively you can achieve the result you expected by directly manipulating the value instead of the object
var uv = new UnitValue(2, "px");
"-uv.value" this will return the Numeric data type with negating the value, in this case it will convert the number 2 to -2
I do see it is working as documented, I would like to hear your view with the above information.
Unary operators (~, !,…
- Don't see your idea?