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 nativePromise
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
1 Answer
Reset to default 3finally()
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.