javascript - Getting "Finally is not a function" in bluebird, why? - Stack Overflow

admin2025-03-19  4

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

Why does finally not exist?

This is client/browser code.

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

Why does finally not exist?

This is client/browser code.

Share Improve this question edited Apr 27, 2018 at 13:55 Liam 29.8k28 gold badges138 silver badges202 bronze badges asked Sep 22, 2017 at 14:39 Ian WarburtonIan Warburton 15.7k24 gold badges116 silver badges208 bronze badges 8
  • 2 It feels that you didn't use installation section from the docs, and using native Promise on instead of bluebird. Have you done this? – Andrey Commented Sep 22, 2017 at 14:44
  • I'm not using node. – Ian Warburton Commented Sep 22, 2017 at 14:45
  • 1 Check your script path, I tested and it works fine, check this out jsbin./labixiwiru/edit?html,js,console,output – AngelSalazar Commented Sep 22, 2017 at 14:48
  • I have two pages and was testing it from the one without a script reference. – Ian Warburton Commented Sep 22, 2017 at 14:51
  • 1 Do not delete this question, it was the top google hit and help resolve my issue. – Aaron McMillin Commented Jul 4, 2018 at 15:43
 |  Show 3 more ments

1 Answer 1

Reset to default 3

finally() is not a function for a promise

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

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

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1742363153a209729.html

最新回复(0)