jQuery's deferred API is bloated and predates promise libraries. Once they realised how useful promises were, they added a then
(or previosly, pipe
) method, however it they failed to get it 100% right.
How come the JS API on Mozilla doesn't have done()
?
It's completely unnecessary. All Promises/A+ compatible implementations (which includes ES6) only need a single method: .then()
. It's completely universal, you can do everything with it - it's the primitive of promises.
What if I want to have a done()
functionality in JavaScript? What do I do?
Well, you could implement it yourself:
Promise.prototype.done = function(cb) { // or function(...cbs) for (let cb of cbs) …
this.then(cb).then(null, function(err) { /* ignore */ });
return this;
};
But as you can see from that, it's not very useful actually. It doesn't chain, and it ignores exceptions, so you should just use then
everywhere.