4 ms·
Promises/A+ - understanding the spec through implementation
- AdrianRossouw 13y agoI feel like promises are slowly becoming more accepted and widely used through the javascript community. I know I didn't immediately see the point of them, and had to sit down and learn to use them properly before I was convinced.
- jbmartin 13y agoI found Async Javsacript by Trevor Burnham super helpful for learning how use promises properly. However, it doesn't cover the javascript implementation of a promise (uses jQuery), so this is a nice blog post complementing that material.
- trafficlight 13y agoI was in the same boat until I ran into a problem that was perfectly solved by promises. Took a while to get to that point, though.
- jbmartin 13y agojQuery loosely follows the Promises/A spec [1], so Q.js [2] might have been better choice. [1] http://domenic.me/2012/10/14/youre-missing-the-point-of-promises/ http://domenic.me/2012/10/14/youre-missing-the-point-of-prom... [2] http://documentup.com/kriskowal/q/# http://documentup.com/kriskowal/q/#
- SeanDav 13y agoI disagree. I would rather see examples of Promises in pure Javascript. It is the more general approach and not everyone uses jQuery.
- jbmartin 13y agoMy mistake. I thought the blog post was about using jQuery. I totally agree with you.
- AdrianRossouw 13y agosince jquery 1.8 they fixed the most outrageous limitation with their deferred implementation (then should return a new promise), and I actually prefer their implementation. that said, i make use of underscore.deferred, which is the jquery implementation as an underscore mixin.
- ville 13y agoAnother nice resource on implementing promises are the design documentation on Q (promise library) repository: https://github.com/kriskowal/q/blob/master/design/README.js https://github.com/kriskowal/q/blob/master/design/README.js (HN discussion: https://news.ycombinator.com/item?id=4767941 https://news.ycombinator.com/item?id=4767941)
- chenglou 13y agoDoes anyone know if ES6's `yield` operator can potentially satisfy most of the goal of promises? It's still confusing after a while.
- tieTYT 13y agoWhat's a promise? This article seems to assume you know that when you start reading. Here's my understanding: Sometimes in code you get into callback hell. A callback calls a callback calls a callback. Your code starts to grow horizontally more than vertically like this: callback1 callback2 callback3 callback3ReactionToFailure callback2ReactionToFailure callback1ReactionToFailure As a result, the code is hard to read because it doesn't flow sequentially. Promises are a solution to that problem. They let you take something that would be callback hell and write it sequentially. Keep in mind it's the blind leading the blind here. I just learned this term a month ago. Please correct me if I'm wrong. That said, I found http://promises-aplus.github.io/promises-spec/#terminology http://promises-aplus.github.io/promises-spec/#terminology to be more informative than the article itself (no offense)
- islon 13y agoyou can use core.async [1] on clojurescript right now to mitigate callback hell (or if you love go aync/channels) [1] http://www.infoq.com/news/2013/07/core-async http://www.infoq.com/news/2013/07/core-async