3 ms·
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()
by jahewson 15y ago
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
- gozala 15y agoI 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
- jahewson 15y agoEdit: cool, it works!
- deleted 15y ago[deleted]
- streptomycin 15y agoThe typoed syntax was nicer than the real syntax, unfortunately.
- ricardobeat 15y agoYou 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.
- skrebbel 15y agoThat, 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.