It should be noted that there are no synchronous calls available in the JS Object Model, and this is on purpose. The proposal to use promises is just a different async pattern, but that's okay…
It is possible to artificially 'force' the scripts to work in a synchronous manner using various techniques, but there's really no reason to.
Async patterns (direct callback from
executeQueryAsync is actually quite straight forward, it just follows a slightly different execution path when you’re reading down your code than using a synchronous model.
In general the pattern works like this:
- Load one or many client objects (
instruct SharePoint you want to retrieve one or many pieces of
- Instruct the framework to execute
executeQueryAsync and provide
two callbacks as parameters; the first for the case where the call
succeeds, and the second in case the calls encounters an error
- Inside of your initial success callback, continue the optimal
execution path – perhaps loading more client objects and calling
executeQueryAsync again and providing success and failure handlers
once again (these could be the same functions over and over, or
separate functions, or anonymous functions defined inline)
The execution flow can get messy if you’re not careful, but does not need to be significantly more complicated than a standard synchronous format.
JS execution with the JSOM in SharePoint works quite well with the async patterns provided – I encourage people to give them a chance even though they’re not what you might be used to!