javascript 在 bluebird 中得到“最终不是一个函数”,为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46367341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 06:38:01  来源:igfitidea点击:

Getting "Finally is not a function" in bluebird, why?

javascriptbluebird

提问by Ian Warburton

I have included Bluebird like so...

我已经像这样包括了蓝鸟......

<script src="../../js/libs/bluebird.min.js" type="text/javascript"></script>

When I run the following code...

当我运行以下代码时...

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

I get...

我得到...

TypeError: requestEvent(...).then(...).finally is not a function

TypeError: requestEvent(...).then(...).finally 不是函数

Why does finally not exist?

为什么最终不存在?

This is client/browser code.

这是客户端/浏览器代码。

回答by Temani Afif

finally()is not a function for a promise

finally()不是承诺的功能

Read this : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

阅读:https: //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

You need to check if the path of bluebird is correct or not.

您需要检查 bluebird 的路径是否正确。

Update 2018:.finally()is now(TC39 stage 4; finished) part of the official specification now as you can see in the same link above or in this specific page. However not many browsers support it yet.

更新2018:.finally()现在(TC39第4阶段;成品)的正式规范的一部分,现在,你可以在上面或相同的链接看到在这个特定的页面。然而,还没有多少浏览器支持它