Closed bashilbers closed 10 years ago
@bashilbers catch
is part of the ES6 Promise standard, so it is allowed as a method in ES5+ environments. For ES3 environments, you can use the alias otherwise
.
However, "undefined is not a function" sounds like an unrelated error. Are you sure you're calling catch
on a when.js promise, and not some other promise or promise-like, such as a jQuery deferred?
Hey @bashilbers,
There are two ways you can use catch
in older browsers: a) quote it, b) use an alias.
importFeed().then(function() {
self.log.info('Importing feed done');
})['catch'](function(e) { });
otherwise()
is an alias for catch()
. See the docs: https://github.com/cujojs/when/blob/master/docs/api.md#promisecatch
That Mozilla page is a bit confusing. The first sentence seems to be outdated or ES3-specific. Have a look at the ES5 section of that Mozilla link for info on ES5 (and later) envs.
I'm using otherwise
now, which is working for me
Cool, glad that worked for you. There are aliases for the other ES3 reserved words as well, eg finally
-> ensure
.
This is my script:
My developer console says this: Uncaught TypeError: undefined is not a function
catch
is on the reserved list: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Reserved_Wordscite: "...may not be used as ... method"
So, how do I keep track of async errors when I cant call catch on my promise?