完成函数 kriskowal 的 q 的含义

Meaning of done function kriskowal's q

done 函数用于结束承诺链,例如:

foo()
.then(function () {
    return "bar";
})
.done();

来自项目link:https://github.com/kriskowal/q

When you get to the end of a chain of promises, you should either return the last promise or end the chain.

"end the chain"到底是什么意思?有什么影响?

这个网站有很好的解释

http://www.mattgreer.org/articles/promises-in-wicked-detail/

这是主题下的文字:done() to the Rescue

done() can be called whenever then() can. The key differences are it does not return a promise, and any unhandled exception inside of done() is not captured by the promise implementation. In other words, done() represents when the entire promise chain has fully resolved.

以及站点示例中使用的代码示例。

 getSomeJson().done(function(json) {
  // when this throws, it won't be swallowed
  var obj = JSON.parse(json);
  console.log(obj);
});

进一步阅读 q 的 github https://github.com/kriskowal/q/wiki/API-Reference#promisedoneonfulfilled-onrejected-onprogress