Hi Paul,
Thank you for the in depth answer, I think everyone will appreciate such a thorough explanation of JQuery deferred object execution order.
To answer your question as to what was not working for me, it was simply the fact that I was expecting the following execution order.
And about my code. It is a bit more complex than my simple example. I have a function that builds up a promise object based on the needs of various custom JS components on a SP page. I do this because sometimes the components want information from the same lists and libraries, so instead of them calling SPServices directly they receive a promise and wait for it to resolve. Since I expected completefunc() to execute first, it made for some weird results.
Once again that you for the awesome examples.
Ricardo
Thank you for the in depth answer, I think everyone will appreciate such a thorough explanation of JQuery deferred object execution order.
To answer your question as to what was not working for me, it was simply the fact that I was expecting the following execution order.
completefunc()
undefined
done()
then() Document success
then(2)
done(1)
then(3)
It just wasn't obvious to me that completefunc() would execute after all promises were resolved.And about my code. It is a bit more complex than my simple example. I have a function that builds up a promise object based on the needs of various custom JS components on a SP page. I do this because sometimes the components want information from the same lists and libraries, so instead of them calling SPServices directly they receive a promise and wait for it to resolve. Since I expected completefunc() to execute first, it made for some weird results.
Once again that you for the awesome examples.
Ricardo