【文件属性】:
文件名称:thoughts-n-findings-on-promises:帮助学习的 Promise 文章
文件大小:2KB
文件格式:ZIP
更新时间:2021-06-20 02:01:18
JavaScript
#承诺
##什么?
通常用于使使用异步代码更愉快的抽象。
改变这一点:
myAsyncMethod(input, function(err, results) {
// Work on results
})
对此:
aPromise = myAsyncMethodPromise(input)
或者想到另一种方式,这个:
myAsyncMethod(input, output)
对此:
promisedOutput = myAsyncMethodPromise(input)
为什么promisedOutput而不仅仅是output ? 因为该行是在真正的工作完成之前执行的。
它们提供了“同步函数和异步函数之间的直接对应关系”。 -
同步函数返回值并抛出异常。
异步函数不能返回值。 他们可以,但他们需要很长时间。 他们不能抛出异常,因为没有什么地方可以捕获这些异常
【文件预览】:
thoughts-n-findings-on-promises-master
----promise-and-callback.js(702B)
----README.md(2KB)