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?
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?
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()
.