Why do I get the error message “Unable to get property ‘done’ of undefined or null reference” when I run the following code?
new WinJS.Promise(initFunc).then(function () {
/* do something that returns a promise */
}).done(function () {
/* do something that returns a promise */
}).then(function () {
/* do something that returns a promise */
}).done(function () {
});
You can only call
done()once in a promise chain, and that must be at the end of the chain. In the problematic code, thedone()function is called twice in the promise chain:This problem scenario can happen when your code starts off with two separate promise chains and you end up combining them together at some later point, as follows: