Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isPrototypeOf in indesign

Hi am relativly new to indesign scripting and would like to figure out if an object is a subtype of a class. Example: I want to iterate over all page items and take everything that is not a graphic:

layer = app.activeDocument.layers[layerIndex];

for (i = 0; i < layer.allPageItems.length; i++) {
  alert(layer.allPageItems[i].reflect.name)
  if(layer.allPageItems[i].isPrototypeOf (Graphic) ) {
    alert("Graphic");
  } else {
    ....
  }
}

howver the if nver matches. Are there any examples of how to use isPrototypeOf? What do I have to do to test if an object is of a certain type or a subclass of it?

edit: To clarify, I am trying to test if I have an Instance of anything that inherited from Graphic.

But as far as I can see now that seems to be impossible.

like image 336
ted Avatar asked Sep 05 '26 04:09

ted


1 Answers

You probably want the instanceof operator.

if (layer.allPageItems[i] instanceof Graphic) {
    alert("Graphic");
} else {
    ....
}

You could also use isPrototypeOf but you have to reverse the order and get the prototype itself, not the constructor. So it would look like this:

if (Graphic.prototype.isPrototypeOf(layer.allPageItems[i])) {
    alert("Graphic");
} else {
    ....
}
like image 171
Matthew Crumley Avatar answered Sep 07 '26 19:09

Matthew Crumley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!