gpt4 book ai didi

javascript - 完成函数 kriskowal 的 q 的含义

转载 作者:行者123 更新时间:2023-12-03 04:33:25 26 4
gpt4 key购买 nike

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

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

来自项目链接: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.

“结束链条”到底是什么意思?有何影响?

最佳答案

这个网站有很好的解释

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

以下是主题下的文本:done() 来救援

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

关于javascript - 完成函数 kriskowal 的 q 的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43397351/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com