3 ms·
In your code, loadData() function knows that the data is being fetched asynchronously. In the posted code, loadData() doesn't have to know whether getData() wor
by brlewis 13y ago
In your code, loadData() function knows that the data is being fetched asynchronously. In the posted code, loadData() doesn't have to know whether getData() works synchronously or asynchronously.
- taeric 13y agoMeh. With higher order functions, this could be achieved as well. I was focusing on the "hide the loading screen" portion of the example. And, honestly, it is not obvious to me when the loading screen gets hidden. In the callback one, that is much more obvious. (Granted, this is as much from familiarity.)
- brlewis 13y agoHiding synchronous vs. asynchronous with higher-order functions means doing it with callbacks. It's generally hard to take a function that was originally written to run synchronously and change it to run asynchronously without changing the way it's called. I don't see this as world-changing either, but I understand why people like it.