Obi-wan Kenobi‌ the (function(){}()) pattern is called and self-executing anonymous function. Because javascript has function-based scope, it is used to isolate the variables in the script as not to pollute the global namespace. While in this, and many other simple scripts is not really needed, since the engine in which the script runs is not persistent, it does not hurt and it's a good habit to get into for when you start to write much larger scripts. There are quite a few resources about this online, for example: http://stackoverflow.com/questions/14322708/what-is-self-executing-anonymous-function-or-what-is-this-code-doing The try-catch here is very useful here: consider what happens if a document has no tables: app.activeDocument.stories.everyItem().tables.everyItem() returns and empty specifier, that has no "cells" object, so you would get an error. Or, taking things to a bit more extreme, what if there is no document opened? I agree it's not the nicest, most elegant or expressive way of doing it, but it works in a pinch (to be read as: don't do as i do).
... View more