0

I’ve seen both in code samples; for instance, in Adobe InDesign CS6 JavaScript Scripting Guide:

app.documents.item(0).pages.item(0)

myDoc.pages[0] 

Are they interchangeable? Which one’s the best pratice?

1 Answers1

0

There's not really an interesting answer here, yes they are interchangeable and which one you choose is up to you. I did a quick performance test, and the brackets operator seems to work slightly faster, but just by a factor of 1.1, so it should not make much of a difference.

The only difference between the two (that does not apply to your scenario) is that item() can also be used to address an item by name, as in myDoc.paragraphStyles('headline'); and is therefore in turn interchangeable with itemByName().

mdomino
  • 1,195
  • 1
  • 8
  • 22
  • Yes, `item()` and `itemByName()` are interchangeable within the context that @mdomino provides, i.e. when its usage addresses an item by name. However it's worth noting that; [`item()`](http://jongware.mit.edu/idcs6js/pc_Documents.html#item) returns the document with either the specified _index_ or _name_. Yet, [`itemByName()`](http://jongware.mit.edu/idcs6js/pc_Documents.html#itemByName) returns the document with the specified _name_ only. So, interchangeability depends upon usage/context. – RobC Oct 09 '19 at 08:16