Promises I find rather ugly to read. So far Im liking arrow functions and template strings. Async/await I'm looking forward to in ES7.
What exactly did you have in mind other than "new Promise()" to create a promise?
it's a little much
11–20 of 144 posts
Promises I find rather ugly to read. So far Im liking arrow functions and template strings. Async/await I'm looking forward to in ES7.
What exactly did you have in mind other than "new Promise()" to create a promise?
it's a little much
Wow. I can't believe template strings ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... ) aren't in this list. I'm incredibly excited to start having those at my disposal.
Generally though, is it reasonable for features such as these to be included at the language level? I primarily use ES5 JavaScript so I'm used to pulling in a decent amount of modules (in this case handlebars, underscore, etc.) for things like templating.
But I will be relieved to have a language-standard solution to what feels like such a common problem for the environments in which JS is used primarily, despite the tradeoff that's made in accessibility due to feature bloat.
ie. I can't write:
return new Promise((resolve, reject) => {
// Do some stuff, call resolve()/reject() on success/failure.
}).then((step1Val, resolve, reject) => {
// Do some stuff, call resolve()/reject() on success/failure.
// But this doesn't actually work, because the "then" callback
// doesn't get resolve/reject as args.
});
Instead I'm having to write this as the following, which is more verbose: return new Promise((resolve, reject) => {
// Do some stuff, call resolve()/reject() on success/failure.
}).then(new Promise((resolve, reject) = {
// Do some stuff, call resolve()/reject() on success/failure.
// But this way I don't get access to step1Val.
}));
Another bummer of this style is that that the second step doesn't get access to the first step's value.I'm new to Javascript, and am wondering if I be writing ES6 instead of ES5. Is that a good idea, or should I wait a few months/years?
ES5 is the current standard in all major browsers, so using its functionality could be considered "safe". Thankfully we have transpilers (will convert your ES6 code to ES5), so you can use ES6 features in production today - just remember they are converted to an ES5 implementation of said functionality.
I've just been playing with Promises and like them a lot. But one thing I find strange is that ".then()" creates a new promise, but with no way to reject it. ie. I can't write: return new Promise((resolve, reject) => { // Do some stuff, call resolve()/reject() on success/failure. }).then((step1Val, resolve, reject) => { // Do some stuff, call resolve()/reject() on success/failure. // But this doesn't actually work, b…
IMO you should use Babel and take advantage.
I've just been playing with Promises and like them a lot. But one thing I find strange is that ".then()" creates a new promise, but with no way to reject it. ie. I can't write: return new Promise((resolve, reject) => { // Do some stuff, call resolve()/reject() on success/failure. }).then((step1Val, resolve, reject) => { // Do some stuff, call resolve()/reject() on success/failure. // But this doesn't actually work, b…
I've just been playing with Promises and like them a lot. But one thing I find strange is that ".then()" creates a new promise, but with no way to reject it. ie. I can't write: return new Promise((resolve, reject) => { // Do some stuff, call resolve()/reject() on success/failure. }).then((step1Val, resolve, reject) => { // Do some stuff, call resolve()/reject() on success/failure. // But this doesn't actually work, b…
I've just been playing with Promises and like them a lot. But one thing I find strange is that ".then()" creates a new promise, but with no way to reject it. ie. I can't write: return new Promise((resolve, reject) => { // Do some stuff, call resolve()/reject() on success/failure. }).then((step1Val, resolve, reject) => { // Do some stuff, call resolve()/reject() on success/failure. // But this doesn't actually work, b…
There is a way to reject it in the .then() callback. You just throw.
Also how do you return a value from the second callback? Just return?
If throw and return work that way for then() functions, why not the same for the initial function?