This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(cb=>{ | |
//setTimeout() wraps the callback cb and makes it run in | |
//another execution context, or "thread" | |
//the term thread is not accurate but may provide some ease of understanding | |
//the different contexts that help to achieve asynchrony | |
setTimeout(()=>{ | |
cb() | |
},0); | |
console.log("B") | |
})(()=>{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(cb=>{ | |
//setTimeout() wraps the callback cb and makes it run in | |
//another execution context, or "thread" | |
//the term thread is not accurate but may provide some ease of understanding | |
//the different contexts that help to achieve asynchrony | |
setTimeout(()=>{ | |
cb() | |
},0); | |
console.log("B") | |
})(()=>{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(cb=>{ //the code runs as | |
cb(); | |
console.log("B") | |
})(()=>{ | |
console.log("C") | |
}); | |
console.log("A") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((a)=>{ //"linearized" code without callbacks, an async-esque way to "linearize" asynchronous code | |
let value=++a | |
value*=value | |
value=++value | |
console.log(value); | |
})(1); //note the semicolon | |
//example below might seem far-fetched/over-the-top but it does prove that linear | |
//code may be much easier to read than code with callback | |
((a)=>{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((a,cb)=>{ | |
++a; | |
cb(a) | |
})/*entry point>>>>*/(1,(b)=>{ | |
b*=b; | |
((c,cb)=>{ | |
cb(c) | |
})(b,(d)=>{ | |
++d; | |
((e,cb)=>{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((a,cb)=>{ | |
++a; | |
cb(a) | |
})(1,(b)=>{ | |
b*=b; | |
((c,cb)=>{ | |
cb(c) | |
})(b,(d)=>{ | |
++d; | |
((e,cb)=>{ |