News for hackers. Stuff that matters.
Re:Write logic, not mechanics by jahewson on Thursday April 19, 2012 @10:53AM (#3863271)
The code doesn't actually work though, the very first example is broken:

    function sum(a, b) { return a + b }
    sum = promised(sum)

    var a = defer()         // make promise
    var b = sum(a, 1)
    var b = sum(b, 5)
    console.log(b)          // eventually prints => 17
    a.resolve(11)           // fulfill promise
Prints:

    [object Object]15
Re:Write logic, not mechanics by gozala on Thursday April 19, 2012 @11:05AM (#3863335)
I have already fixed that, it was a typo, I meant following instead:

    var deferred = defer()          // make promise
    var a = deferred.promise
    var b = sum(a, 1)
    var c = sum(b, 5)
    console.log(c)                  // eventually prints => 17
    deferred.resolve(11)            // fulfill promise
Re:Write logic, not mechanics by streptomycin on Thursday April 19, 2012 @11:57AM (#3863596)
The typoed syntax was nicer than the real syntax, unfortunately.
Re:Write logic, not mechanics by ricardobeat on Thursday April 19, 2012 @12:14PM (#3863706)
You were writing an article about it and didn't get it right on the first time - maybe that's the reason more people don't use it.
Re:Write logic, not mechanics by skrebbel on Thursday April 19, 2012 @12:59PM (#3863973)
That, or a majority of the JS coding crowd is too novice to appreciate maintainable code better than copying and pasting "simple" plumbing all over the place.
Re:Write logic, not mechanics by jahewson on Thursday April 19, 2012 @11:10AM (#3863360)
Edit: cool, it works!