To me promises are code bloat junk for people too stupid to program.

Given that JavaScript is single threaded, the only time they would serve any point is for events... but what the blazes do they ACTUALLY do that normal event handlers don't, and how do they make clearer code?

Your article does an AMAZING job of showing the card stacked garbage code practices that could delude people into thinking that promises serve a purpose. It's like you chose the worst normal code possible in order to make promises look good.

The coin-flip example is EXACTLY what I mean. You just made the code execution order MORE confusing. How the blue blazes is that an improvement?

Same for the "wait for it to finish" and the derpy "let's chain together then for nothing" trash. IT's dumb enough how halfwit monuments to developer ignorance, incompetence, and ineptitude like jQuery encouraged that type of code construction, without it having been sleazed into the language any-old-way. It is the OPPOSITE of code clarity, efficiency, and it sure as shine-ola doesn't make a blasted thing easier, simpler, or better... unless of course you don't know enough programming to have a valid opinion on the topic.

It reeks of the same scale of idiocy as those who use arrow functions with foreach/map for one-liners that would be cleaner, simpler, and a thousand times faster executing with for/of, or the equally derpy practice of tripling the code size to break ever blasted line of code out into its own separate function... or in the case of the "include" / type="module" fanboys it's own flipping separate file as well.

But what can one expect when your examples on codepen all violate good practices with outdated rubbish and bad practices like innerHTML, non-semantic markup, scripting only elements static in the markup, map/callback for nothing other than making the page slower...

Guess that's what happens when people think halfwit trash like jQuery or React do anything but piss on every project they're applied to.

Let’s take something simple, your data fetching example.

The markup has span for nothing, spaces improperly placed for inline-level elements (so you don’t even know how to use HTML?), etc, etc… so first let’s trim off the fat.

Users result:<span id="users">...</span>

Then let’s do it the “old” way.

var
listOfUserIds = [1, 2, 3, 4, 5],
spanUsers = document.getElementById('users');

function userList(data) {
if (!data) return;
spanUsers.textContent = '';
function next() {
if (data.length) {
spanUsers.textContent += ' username' + data.shift();
setTimeout(next, 1000);
}
}
setTimeout(next, 1000);
}

userList(listOfUserIds);

You’ve got 403 bytes of cryptic code doing 363 bytes of clear code with clear logic’s job. HOW is this wreck of yours:

const getUser = (userId) => new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
name: `username${userId}`
});
}, 1000);
});
const listOfUserIds = [1, 2, 3, 4, 5];
Promise.all(listOfUserIds.map(userId => getUser(userId))).then((users) => {
const result = users.reduce((a, b) => `${a} ${b.name}`, "");
document.getElementById("users").innerHTML = result;
});

Easier, simpler, or better?!? Same goes for your cryptic hard to follow “waiting mid-chain” … how is this mess:

const promise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, 2000);
}).then(result => {
document.getElementById("then1").innerHTML = "Done!";
}).then(result => {
return new Promise((resolve, reject) => {
setTimeout(() => {
document.getElementById("then2").innerHTML = "Done!";
resolve();
}, 3000);
});
}).then(() => {
document.getElementById("then3").innerHTML = "Done!";
});

Better than how that would/should be handled in old-school vanilla as:

function setTextChain(id, text, delay, nextCallback) {
document.getElementById(id).textContent = text;
if (nextCallback) setTimeout(nextCallback, delay);
}
setTextChain('then1', 'Done!', 2000, function() {
setTextChain('then2', 'Done!, 3000, function() {
setTextChain('then3', 'Done!');
});
});

To me, after many decades of programming, promises in JavaScript seem like a pointless, wasteful addition to the language by people who probably shouldn’t be programming in the first place.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store