'Promise-based Http client' 是什么意思?
what does the term 'Promise-based Http client' mean?
在浏览 Redux 中间件时,我遇到了 'Promise-based HTTP client' 从浏览器发出 Ajax 请求的 Axios。任何人都可以解释一下这个术语和一些关于 axios 的信息吗?
基于承诺的客户端returns承诺而不是接受回调。
在 Promise's
出现之前,有一个叫做 Callback
的东西可以处理异步 calls/code。但是回调的主要问题是,当它嵌套并且嵌套得更多时,它会变得非常混乱,甚至对于代码编写者来说也更难理解。
为了让它更干净一些 Promise
出现在本质上更干净的图片中,避免 nodejs 编程中的回调地狱问题。
此外,概念 async/await
也最适合使用 promise 而不是回调。
希望你现在明白了。如有任何疑问,请在下方评论。
来自MDN:
A Promise
is a proxy for a value not necessarily known when the
promise is created. It allows you to associate handlers with an
asynchronous action's eventual success value or failure reason. This
lets asynchronous methods return values like synchronous methods:
instead of immediately returning the final value, the asynchronous
method returns a promise to supply the value at some point in the
future.
A Promise
is in one of these states:
- pending: initial state, neither fulfilled nor rejected.
- fulfilled: meaning that the operation was completed successfully.
- rejected: meaning that the operation failed.
在浏览 Redux 中间件时,我遇到了 'Promise-based HTTP client' 从浏览器发出 Ajax 请求的 Axios。任何人都可以解释一下这个术语和一些关于 axios 的信息吗?
基于承诺的客户端returns承诺而不是接受回调。
在 Promise's
出现之前,有一个叫做 Callback
的东西可以处理异步 calls/code。但是回调的主要问题是,当它嵌套并且嵌套得更多时,它会变得非常混乱,甚至对于代码编写者来说也更难理解。
为了让它更干净一些 Promise
出现在本质上更干净的图片中,避免 nodejs 编程中的回调地狱问题。
此外,概念 async/await
也最适合使用 promise 而不是回调。
希望你现在明白了。如有任何疑问,请在下方评论。
来自MDN:
A
Promise
is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers with an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point in the future.A
Promise
is in one of these states:
- pending: initial state, neither fulfilled nor rejected.
- fulfilled: meaning that the operation was completed successfully.
- rejected: meaning that the operation failed.