Indiscripts

Automating InDesign since 2009

Tag : Operators

Let's Play with JS Array Objects (in ExtendScript)

IdExtenso provides a new ArrayAs2D module that unleashes the hidden strengths of ExtendScript operators. With this toy, you can now write code that adds, multiplies, evaluates 2D points or vectors. For example, if you develop an InDesign script based on Bézier curves or working on polygonal paths, all calculations of points, distances, normalized vectors, etc. become wonderfully compact…

Continue reading...

Make `&` (almost) Behave as a Reference Operator

Suppose you have an ExtendScript class (I mean, “prototype”) whose methods essentially return new object instances. As an obvious example, consider the concat or slice methods of Array.prototype. They always produce a new array rather than reworking the existing one. There are situations where you want to update the calling object —and make this explicit in the code— while still leveraging the methods already available…

Continue reading...

Why You Should Never Use `x==null` in ExtendScript

The Japanese scripter あるふぁ found a bug affecting any ExtendScript code based on ...==null. This is not a critical issue (because experienced developers never use such condition!) but the case provides the opportunity to summarize important rules regarding falsey values and the equality operator…

Continue reading...

Operator Overloading with ExtendScript

Operator overloading in JavaScript is a controversial issue. Actually, this dangerous feature has been rejected in ECMAScript 4. However, ExtendScript allows you to override the behavior of many mathematical and logical operators on a class-by-class basis since CS2.

Continue reading...