3 ms·
If you have callbacks, you end up with hard to read and debug code. If you have transparent async, then: Then how do you know what blocks and what doesn't ? W
by sametmax 9y ago
If you have callbacks, you end up with hard to read and debug code.
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 ?
- balfirevic 9y agoWhy would you need to know, except in some special cases? If you're using async/await, your next line is not executing anyway until the result comes, blocking or not.
- sametmax 9y agoBecause otherwise you block the even loop or mismatch life cycle. Espacially reading an unfamiliar code base.
- z3t4 9y agoembrace higher-order functions. Use named functions and closures! 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); } }