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 live online training, plus books, videos, and digital content from nearly 200 publishers.