我已经像这样包含了 Bluebird...
<script src="../../js/libs/bluebird.min.js" type="text/javascript"></script>
当我运行以下代码时...
requestEvent(request, src)
.then(function (response) {
...
})
.finally(function () {
...
});
function requestEvent(request, src) {
return new Promise(function (resolve, reject) {
$.ajax({
url: 'mywebsite',
type: "POST",
success: function (response) {
if (response.status == 0) {
reject(response.message);
}
resolve(response);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
reject(XMLHttpRequest.responseText);
}
});
});
}
我明白了...
TypeError: requestEvent(...).then(...).finally is not a function
为什么最终不存在?
这是客户端/浏览器代码。
最佳答案
finally()
不是 Promise 的函数
阅读此内容:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
您需要检查bluebird的路径是否正确。
更新 2018: .finally()
现在(TC39 第 4 阶段;已完成)现在是官方规范的一部分,如您所见在上面的同一链接中或 in this specific page 。然而not many browsers support it yet .
关于javascript - 在bluebird中获取 "Finally is not a function",为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46367341/