by q3k · 9y ago · 0 comments
Other languages come either with great concurrency support out of the box (Go, Erlang) or enough constructs to implement cooperative schedulers without having to specify async/await (Lua).
[Edit] JS has long been criticized (fairly or not) for offering clunky "concurrency" strategies. If you must down vote, please have the decency to offer a counter perspective.
If you have transparent async, then:
Then how do you know what blocks and what doesn't ? What's asynchronous and what's going to trigger a switch ? What's a disguised callback and what's the next line ?
What's the solution then ?
example code:
var anchors = document.getElementsByTagName(“a”);
for(var i=0,len=anchors.length; i<len; i++){
alertClickAnchor(i); // Named function
}
function alertClickAnchor(i) { // Closure
anchors[i].onclick = function() {
alert(i);
}
}