jQuery Promises have been around for a while, but I've always slinked away tail between my legs at the mere mention of them. Running might have attracted the beast's attention. Alas, my new project uses Promises religiously. They are actually nifty constructs once you wrap your head around them. I had to stew and mull for about a week before I could grasp the difference Promises and Deferred (I know, what a scrub)
This post is for anyone specifically wondering about Promises vs Deferred. I'm not going to talk about Promises in general--there are already a ton of good articles on that topic.
There is really nothing special about Promises and Deferred--they are both plain ol' JavaScript objects. Every Deferred object has a corresponding Promise object. The Promise is essentially a copy of the Deferred with limited functionality.
When you are running an async operation, you create a Deferred. You can then use it to attach handlers, and more importantly, Resolve or Reject when the operation completes. In the meantime, you get the Deferred's corresponding Promise and return that to your caller.
1 comments:
I like the simplicity of this description....
Post a Comment