Windows 8 无法获取属性';完成';指未定义的或空的引用

Windows 8 无法获取属性';完成';指未定义的或空的引用,windows-8,winjs,Windows 8,Winjs,运行以下代码时,为什么会出现错误消息“无法获取未定义或空引用的属性'done'” new WinJS.Promise(initFunc).then(function () { /* do something that returns a promise */ }).done(function () { /* do something that returns a promise */ }).then(fu

运行以下代码时,为什么会出现错误消息“无法获取未定义或空引用的属性'done'”

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 () {
});

在承诺链中只能调用一次
done()
,并且必须在承诺链的末尾。在有问题的代码中,
done()
函数在承诺链中被调用两次:

new WinJS.Promise(initFunc).then(function () {
}).done(function () {     <====== done() is incorrectly called here--should be then()
}).then(function () {     <====== the call to then() here will throw an error
}).done(function () {             
});
new WinJS.Promise(initFunc).then(函数(){

}).done(function(){在承诺链中只能调用一次
done()
,并且必须在链的末尾。在有问题的代码中,
done()
函数在承诺链中被调用两次:

new WinJS.Promise(initFunc).then(function () {
}).done(function () {     <====== done() is incorrectly called here--should be then()
}).then(function () {     <====== the call to then() here will throw an error
}).done(function () {             
});
new WinJS.Promise(initFunc).then(函数(){

}).done(函数(){您只需在以下情况下就会得到相同的错误:

new WinJS.Promise(initFunc).then(function () {
}).done(function () {
});
因为您在
中的代码没有返回调用
done
的承诺

new WinJS.Promise(initFunc).then(function () {
    // Return a promise in here
    // Ex.:
    return WinJS.Promise.timeout(1000);
}).done(function () {
});

回到您的初始代码,正如您在回答中提到的,您不应该将多个
done
链接在一起。

您只会在以下方面得到相同的错误:

new WinJS.Promise(initFunc).then(function () {
}).done(function () {
});
因为您在
中的代码没有返回调用
done
的承诺

new WinJS.Promise(initFunc).then(function () {
    // Return a promise in here
    // Ex.:
    return WinJS.Promise.timeout(1000);
}).done(function () {
});

回到您的初始代码,正如您在回答中提到的,您不应该将多个
done
链接在一起。

您是正确的。我最初在代码中有这样的注释,但为了简化示例而删除了它们。我将重新添加它们。您是正确的。我最初在代码中有这样的注释,但是t删除它们以简化示例。我将重新添加它们。您可以使用.join合并到承诺链,在两者都完成时完成。我认为这就是您的字符串要达到的目的。只需使用的结果。然后,您就可以使用了。join合并到承诺链,在两者都完成时完成。我认为这就是您的字符串要达到的目的开始。只需使用测试结果。然后,你就会很好