News for hackers. Stuff that matters.
Re:Promises/A+ - understanding the spec through implementation by AdrianRossouw on Wednesday August 21, 2013 @11:37AM (#6251058)
I 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.

Re:Promises/A+ - understanding the spec through implementation by jbmartin on Wednesday August 21, 2013 @12:05PM (#6251258)
I 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.
Re:Promises/A+ - understanding the spec through implementation by trafficlight on Wednesday August 21, 2013 @12:46PM (#6251591)
I 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.
Re:Promises/A+ - understanding the spec through implementation by tieTYT on Wednesday August 21, 2013 @03:46PM (#6252870)
What'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 to be more informative than the article itself (no offense)

Re:Promises/A+ - understanding the spec through implementation by ville on Wednesday August 21, 2013 @01:23PM (#6251881)
Another nice resource on implementing promises are the design documentation on Q (promise library) repository: https://github.com/kriskowal/q/blob/master/design/README.js (HN discussion: https://news.ycombinator.com/item?id=4767941)
Re:Promises/A+ - understanding the spec through implementation by chenglou on Wednesday August 21, 2013 @02:13PM (#6252271)
Does anyone know if ES6's `yield` operator can potentially satisfy most of the goal of promises? It's still confusing after a while.
Re:Promises/A+ - understanding the spec through implementation by jbmartin on Wednesday August 21, 2013 @11:58AM (#6251201)
jQuery 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-prom... [2] http://documentup.com/kriskowal/q/#

Re:Promises/A+ - understanding the spec through implementation by SeanDav on Wednesday August 21, 2013 @12:09PM (#6251296)
I disagree. I would rather see examples of Promises in pure Javascript. It is the more general approach and not everyone uses jQuery.
Re:Promises/A+ - understanding the spec through implementation by jbmartin on Wednesday August 21, 2013 @12:12PM (#6251326)
My mistake. I thought the blog post was about using jQuery. I totally agree with you.
Re:Promises/A+ - understanding the spec through implementation by AdrianRossouw on Thursday August 22, 2013 @09:21AM (#6256925)
since 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.

Re:Promises/A+ - understanding the spec through implementation by islon on Thursday August 22, 2013 @08:42AM (#6256725)
you 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