Chapter 3Promises and Deferreds
In 2010, I had this conversation with my prolific colleague Mr. Ajax:
- Me:
-
Hey, would you fetch some data from this URL for me, please?
- Mr. Ajax:
-
Iâm on it! Just give me a success callback so I can let you know when Iâm done.
- Me:
-
OK, here you go. Thanks.
- Mr. Ajax:
-
Oh, and you should give me an error callback, too. You know, just in case.
- Me:
-
Good point. Anything else?
- Mr. Ajax:
-
Hey, I noticed that thereâs some code duplication between those two callbacks! You could move that into a third always callback.
- Me:
-
(impatiently) Alright, Iâll refactor them. Tell you what: why donât you run now, and Iâll give you the callbacks later?
- Mr. Ajax:
-
(irately) What do I look like, an EventEmitter?
Thankfully, jQuery ...
Get Async JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.